# Share template

{% patch /%}
{% path text="/v1/template/share" /%}

Manage team-level access to a template within an organization. Grant or revoke access for one or more teams in a single request.

Common use cases include:

-   Granting **Use** access so another team can create documents from the template
-   Granting **Edit** access so another team can modify the template
-   Revoking previously granted access

## How sharing works

Sharing is configured per team:

-   Provide an array of team entries in the request body.
-   Each entry includes a `teamId` and an `action`.
-   When `action` is `Grant`, `accessLevel` is required.

The API applies your requested changes to the template's team-sharing configuration.

### Actions

-   **Grant**: Assign an access level to a team.
-   **Revoke**: Remove a team's access.

### Access levels

-   **Use**: The team can use the template to create documents.
-   **Edit**: The team can edit the template and also use it to create documents.

## Code snippet

The following example shares a template with multiple teams, granting different access levels and revoking access for another team.

{% codetab %}

cURL

```shell
curl -X PATCH 'https://api.boldsign.com/v1/template/share?templateId=54e67b1a-af13-4370-91ed-031343170578' \
-H 'Content-Type: application/json' \
-H 'X-API-KEY: {API-KEY}' \
-d '{
    "teams": [
        {
            "teamId": "54e67b1a-af13-4370-91ed-031343170578",
            "action": "Grant",
            "accessLevel": "Edit"
        },
        {
            "teamId": "41b498c3-cbee-488d-8c7c-4dc97a7f31e7",
            "action": "Grant",
            "accessLevel": "Use"
        },
        {
            "teamId": "96d38f94-d636-4215-9f50-ff21d90baba8",
            "action": "Revoke"
        }
    ]
}'
```

C#

```csharp
var apiClient = new ApiClient("YOUR_API_KEY");

var templateClient = new TemplateClient(apiClient);

var shareTemplateRequest = new ShareTemplateRequest
{
    Teams =
    [
        new TemplateTeamShare
        {
            TeamId = "54e67b1a-af13-4370-91ed-031343170578",
            Action = TemplateShareAction.Grant,
            AccessLevel = TemplateAccessLevel.Edit
        },
        new TemplateTeamShare
        {
            TeamId = "41b498c3-cbee-488d-8c7c-4dc97a7f31e7",
            Action = TemplateShareAction.Grant,
            AccessLevel = TemplateAccessLevel.Use
        },
        new TemplateTeamShare
        {
            TeamId = "96d38f94-d636-4215-9f50-ff21d90baba8",
            Action = TemplateShareAction.Revoke
        }
    ]
};

templateClient.ShareTemplate("YOUR_TEMPLATE_ID", shareTemplateRequest);
```

Python

```python
import boldsign

configuration = boldsign.Configuration(host = "https://api.boldsign.com", api_key="YOUR_API_KEY")

with boldsign.ApiClient(configuration) as api_client:
    template_api = boldsign.TemplateApi(api_client)
    team1 = boldsign.TemplateTeamShareRequest(
        team_id="YOUR_TEAM_ID",
        action="Grant",
        access_level="Use"
    )
    team2 = boldsign.TemplateTeamShareRequest(
        team_id="YOUR_TEAM_ID",
        action="Revoke",
        access_level="Use"
    )
    template_share_request = boldsign.TemplateShareRequest(
        teams=[team1,team2]
    )
    template_api.share_template(
        template_id="YOUR_TEMPLATE_ID",
        template_share_request=template_share_request
    )
```

PHP

```php
<?php require_once "vendor/autoload.php";

use BoldSign\Configuration;
use BoldSign\Api\TemplateApi;

$config = new Configuration();
$config->setHost('https://api.boldsign.com');
$config->setApiKey('YOUR_API_KEY');

$template_api = new TemplateApi($config);
$team = new BoldSign\Model\TemplateTeamShareRequest();
$team->setAccessLevel("Use");
$team->setAction("Grant");
$team->setTeamId("YOUR_TEAM_ID");

$template_request = new BoldSign\Model\TemplateShareRequest();
$template_request->setTeams([$team]);
$template_api->shareTemplate("YOUR_TEMPLATE_ID",$template_request);
```

NodeJS

```js
import { TemplateApi } from "boldsign";

const templateApi = new TemplateApi("https://api.boldsign.com");
templateApi.setApiKey("YOUR_API_KEY");


var templateTeamShareRequest = new TemplateTeamShareRequest();
templateTeamShareRequest.teamId = "YOUR_TEAM_ID";
templateTeamShareRequest.accessLevel = TemplateTeamShareRequest.AccessLevelEnum.Use;
templateTeamShareRequest.action = TemplateTeamShareRequest.ActionEnum.Grant;

var templateShareRequest = new TemplateShareRequest();
templateShareRequest.teams = [templateTeamShareRequest];
templateApi.shareTemplate("YOUR_TEMPLATE_ID", templateShareRequest);
```

Java

```java
ApiClient client = Configuration.getDefaultApiClient();
client.setBasePath("https://api.boldsign.com");
client.setApiKey("YOUR_API_KEY");

TemplateApi templateApi = new TemplateApi(client);
TemplateTeamShareRequest team1 = new TemplateTeamShareRequest();
team1.setTeamId("YOUR_TEAM_ID");
team1.setAction(TemplateTeamShareRequest.ActionEnum.GRANT);
team1.setAccessLevel(TemplateTeamShareRequest.AccessLevelEnum.EDIT);

TemplateShareRequest shareRequest = new TemplateShareRequest();
shareRequest.setTeams(Arrays.asList(team1));

templateApi.shareTemplate("YOUR_TEMPLATE_ID", shareRequest);
```

{% /codetab %}

## Query parameters

{% nestedtable %}

-   {% arguments name="templateId" /%}{% batch datatype="string" /%}{% required /%}
-   The unique identifier of the template to share.

{% /nestedtable %}

## Request body

Provide the list of sharing updates in the `teams` array.

{% nestedtable %}

-   {% arguments name="teams" /%}{% batch datatype="array" /%}
-   Array of team sharing configurations. At least one item must be provided.
    {% nestedtable %}

    -   {% arguments name="teamId" /%}{% batch datatype="string" /%}{% required /%}
    -   The unique identifier of the team to share the template with.

    ---

    -   {% arguments name="action" /%}{% batch datatype="string" /%}{% required /%}
    -   The action to perform. The available values are `Grant` and `Revoke`.
        -   `Grant`: Grants the specified access level to the team
        -   `Revoke`: Revokes the team's access to the template

    ---

    -   {% arguments name="accessLevel" /%}{% batch datatype="string" /%}
    -   The access level to assign to the team. Required when `action` is `Grant`, ignored when `action` is `Revoke`. The available values are:
        -   `Use`: Grants use template access
        -   `Edit`: Grants edit and use access

    ---

    {% /nestedtable %}

{% /nestedtable %}

## Example response

**_200 OK_**

A successful request returns `200` and does not include a response body.

## Error responses

### 400 Bad Request - Team Not Found

One or more team IDs in the request could not be found.

```json
{
    "errorType": "TeamNotFound",
    "error": "Team not found.",
    "teams": ["96d38f94-d636-4215-9f50-ff21d90baba8"]
}
```

### 400 Bad Request - Missing Required Target

The request must include a `teams` array with at least one item.

```json
{
    "errorType": "MissingRequiredTarget",
    "error": "Request must include teams object."
}
```

### 403 Forbidden - Permission Denied

The user does not have permission to modify the template's sharing settings.

```json
{
    "errorType": "PermissionDenied",
    "error": "Template does not exists or you do not have permission to modify this template's sharing settings.",
    "templateId": ["96d38f94-d636-4215-9f50-ff21d90baba8"]
}
```

### 500 Internal Server Error

An unexpected error occurred while processing the request.

```json
{
    "errorType": "InternalServerError",
    "error": "An unexpected error occurred. Please try again later."
}
```
