mirror of
https://github.com/documenso/documenso.git
synced 2026-10-02 17:54:28 +10:00
361 lines
9.5 KiB
Plaintext
361 lines
9.5 KiB
Plaintext
---
|
|
title: Team-Scoped API Access
|
|
description: Use team-scoped API tokens with document and template envelopes.
|
|
---
|
|
|
|
import { Callout } from 'fumadocs-ui/components/callout';
|
|
import { Step, Steps } from 'fumadocs-ui/components/steps';
|
|
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
|
|
|
|
<EnvelopeWarning />
|
|
|
|
<Callout type="warn">
|
|
This guide may not reflect the latest endpoints or parameters. For an always up-to-date reference,
|
|
see the [OpenAPI Reference](https://openapi.documenso.com).
|
|
</Callout>
|
|
|
|
## Team Context
|
|
|
|
<Callout type="info">
|
|
The V2 REST API does not expose `/team/*` endpoints. Create and manage teams, members, and team
|
|
settings in the Documenso web application. This page explains how a team-scoped token applies
|
|
that team context to supported API resources.
|
|
</Callout>
|
|
|
|
The API resolves the team from your token. You do not pass a team ID when creating, listing, or
|
|
using envelopes. The token's team ID determines which resources the request can access.
|
|
|
|
## Team-Scoped API Tokens
|
|
|
|
API tokens in Documenso are always scoped to a specific team. When you create an API token, it is associated with the team you're currently working in.
|
|
|
|
### How Team Scoping Works
|
|
|
|
- Each API token belongs to exactly one team
|
|
- All API operations using that token automatically access that team's resources
|
|
- Documents, templates, and other resources created via the API belong to the token's team
|
|
- You cannot access resources from other teams with a single token
|
|
|
|
### Creating Team-Scoped Tokens
|
|
|
|
{/* prettier-ignore */}
|
|
<Steps>
|
|
<Step>
|
|
Navigate to your team's settings
|
|
</Step>
|
|
<Step>
|
|
Go to **API Tokens**
|
|
</Step>
|
|
<Step>
|
|
Click **Create Token**
|
|
</Step>
|
|
<Step>
|
|
The token will be scoped to the current team
|
|
</Step>
|
|
</Steps>
|
|
|
|
<Callout type="info">
|
|
To work with multiple teams via API, create separate tokens for each team.
|
|
</Callout>
|
|
|
|
### Token Permissions
|
|
|
|
Your API token inherits permissions based on your role in the team:
|
|
|
|
| Role | Permissions |
|
|
| --------- | ------------------------------------------------ |
|
|
| `ADMIN` | Full access to all team resources and settings |
|
|
| `MANAGER` | Create, edit, and delete documents and templates |
|
|
| `MEMBER` | Create and manage own documents |
|
|
|
|
## Working with Team Documents
|
|
|
|
When you use a team-scoped API token, all document operations are automatically scoped to that team.
|
|
|
|
### Create a Team Document
|
|
|
|
Documents created with a team token belong to that team:
|
|
|
|
<Tabs items={['curl', 'TypeScript']}>
|
|
<Tab value="curl">
|
|
```bash
|
|
curl -X POST "https://app.documenso.com/api/v2/envelope/create" \
|
|
-H "Authorization: api_xxxxxxxxxxxxxxxx" \
|
|
-H "Content-Type: multipart/form-data" \
|
|
-F 'payload={
|
|
"type": "DOCUMENT",
|
|
"title": "Team Contract",
|
|
"recipients": [
|
|
{
|
|
"email": "signer@example.com",
|
|
"name": "John Smith",
|
|
"role": "SIGNER"
|
|
}
|
|
]
|
|
}' \
|
|
-F "files=@./contract.pdf;type=application/pdf"
|
|
```
|
|
</Tab>
|
|
<Tab value="TypeScript">
|
|
```typescript
|
|
const TEAM_API_TOKEN = process.env.DOCUMENSO_TEAM_API_TOKEN;
|
|
|
|
const form = new FormData();
|
|
|
|
const payload = {
|
|
type: 'DOCUMENT',
|
|
title: 'Team Contract',
|
|
recipients: [
|
|
{
|
|
email: 'signer@example.com',
|
|
name: 'John Smith',
|
|
role: 'SIGNER',
|
|
},
|
|
],
|
|
};
|
|
|
|
form.append('payload', JSON.stringify(payload));
|
|
form.append('files', fs.createReadStream('./contract.pdf'), {
|
|
contentType: 'application/pdf',
|
|
});
|
|
|
|
const response = await fetch('https://app.documenso.com/api/v2/envelope/create', {
|
|
method: 'POST',
|
|
headers: {
|
|
Authorization: TEAM_API_TOKEN,
|
|
},
|
|
body: form,
|
|
});
|
|
|
|
const { id } = await response.json();
|
|
console.log('Created team document:', id);
|
|
````
|
|
</Tab>
|
|
</Tabs>
|
|
|
|
### List Team Documents
|
|
|
|
Retrieve all documents belonging to the team:
|
|
|
|
<Tabs items={['curl', 'TypeScript']}>
|
|
<Tab value="curl">
|
|
```bash
|
|
# List all team documents
|
|
curl -X GET "https://app.documenso.com/api/v2/envelope?type=DOCUMENT" \
|
|
-H "Authorization: api_xxxxxxxxxxxxxxxx"
|
|
|
|
# Filter by status
|
|
curl -X GET "https://app.documenso.com/api/v2/envelope?type=DOCUMENT&status=PENDING" \
|
|
-H "Authorization: api_xxxxxxxxxxxxxxxx"
|
|
````
|
|
|
|
</Tab>
|
|
<Tab value="TypeScript">
|
|
```typescript
|
|
const response = await fetch('https://app.documenso.com/api/v2/envelope?type=DOCUMENT', {
|
|
method: 'GET',
|
|
headers: {
|
|
Authorization: TEAM_API_TOKEN,
|
|
},
|
|
});
|
|
|
|
const { data, count } = await response.json();
|
|
console.log(`Found ${count} team documents`);
|
|
|
|
````
|
|
</Tab>
|
|
</Tabs>
|
|
|
|
## Working with Team Templates
|
|
|
|
Templates created with a team token are shared across the team.
|
|
|
|
### Create a Team Template
|
|
|
|
<Tabs items={['curl', 'TypeScript']}>
|
|
<Tab value="curl">
|
|
```bash
|
|
curl -X POST "https://app.documenso.com/api/v2/envelope/create" \
|
|
-H "Authorization: api_xxxxxxxxxxxxxxxx" \
|
|
-H "Content-Type: multipart/form-data" \
|
|
-F 'payload={
|
|
"type": "TEMPLATE",
|
|
"title": "NDA Template",
|
|
"recipients": [
|
|
{
|
|
"email": "placeholder@example.com",
|
|
"name": "Signer",
|
|
"role": "SIGNER",
|
|
"fields": [
|
|
{
|
|
"identifier": 0,
|
|
"type": "SIGNATURE",
|
|
"page": 1,
|
|
"positionX": 10,
|
|
"positionY": 80,
|
|
"width": 30,
|
|
"height": 5
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}' \
|
|
-F "files=@./nda-template.pdf;type=application/pdf"
|
|
````
|
|
|
|
</Tab>
|
|
<Tab value="TypeScript">
|
|
```typescript
|
|
const form = new FormData();
|
|
|
|
const payload = {
|
|
type: 'TEMPLATE',
|
|
title: 'NDA Template',
|
|
recipients: [
|
|
{
|
|
email: 'placeholder@example.com',
|
|
name: 'Signer',
|
|
role: 'SIGNER',
|
|
fields: [
|
|
{
|
|
identifier: 0,
|
|
type: 'SIGNATURE',
|
|
page: 1,
|
|
positionX: 10,
|
|
positionY: 80,
|
|
width: 30,
|
|
height: 5,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
form.append('payload', JSON.stringify(payload));
|
|
form.append('files', fs.createReadStream('./nda-template.pdf'), {
|
|
contentType: 'application/pdf',
|
|
});
|
|
|
|
const response = await fetch('https://app.documenso.com/api/v2/envelope/create', {
|
|
method: 'POST',
|
|
headers: {
|
|
Authorization: TEAM_API_TOKEN,
|
|
},
|
|
body: form,
|
|
});
|
|
|
|
const { id } = await response.json();
|
|
console.log('Created team template envelope:', id);
|
|
````
|
|
</Tab>
|
|
</Tabs>
|
|
|
|
### List Team Templates
|
|
|
|
<Tabs items={['curl', 'TypeScript']}>
|
|
<Tab value="curl">
|
|
```bash
|
|
curl -X GET "https://app.documenso.com/api/v2/envelope?type=TEMPLATE" \
|
|
-H "Authorization: api_xxxxxxxxxxxxxxxx"
|
|
````
|
|
|
|
</Tab>
|
|
<Tab value="TypeScript">
|
|
```typescript
|
|
const response = await fetch('https://app.documenso.com/api/v2/envelope?type=TEMPLATE', {
|
|
method: 'GET',
|
|
headers: {
|
|
Authorization: TEAM_API_TOKEN,
|
|
},
|
|
});
|
|
|
|
const { data } = await response.json();
|
|
console.log('Team templates:', data);
|
|
|
|
````
|
|
</Tab>
|
|
</Tabs>
|
|
|
|
## Team Member Roles
|
|
|
|
| Role | Description |
|
|
| --------- | ------------------------------------------------------------------- |
|
|
| `ADMIN` | Full control over team settings, members, and all resources |
|
|
| `MANAGER` | Can manage documents, templates, and view team resources |
|
|
| `MEMBER` | Can create and manage their own documents within the team |
|
|
|
|
### Document Visibility
|
|
|
|
Team documents have visibility settings that control who can access them:
|
|
|
|
| Visibility | Description |
|
|
| ------------------ | ------------------------------------------------ |
|
|
| `EVERYONE` | All team members can view the document |
|
|
| `MANAGER_AND_ABOVE`| Only managers and admins can view |
|
|
| `ADMIN` | Only admins can view |
|
|
|
|
Set visibility when creating a document:
|
|
|
|
```typescript
|
|
const payload = {
|
|
type: 'DOCUMENT',
|
|
title: 'Confidential Agreement',
|
|
visibility: 'ADMIN', // Only team admins can view
|
|
recipients: [...],
|
|
};
|
|
````
|
|
|
|
## Multi-Team Workflow
|
|
|
|
To work with multiple teams, create and manage separate API tokens for each team.
|
|
|
|
### Example: Sync Documents Across Teams
|
|
|
|
```typescript
|
|
// Tokens for different teams
|
|
const SALES_TEAM_TOKEN = process.env.SALES_TEAM_API_TOKEN;
|
|
const LEGAL_TEAM_TOKEN = process.env.LEGAL_TEAM_API_TOKEN;
|
|
|
|
// Get pending documents from sales team
|
|
const salesResponse = await fetch('https://app.documenso.com/api/v2/envelope?type=DOCUMENT&status=PENDING', {
|
|
headers: { Authorization: SALES_TEAM_TOKEN },
|
|
});
|
|
const salesDocs = await salesResponse.json();
|
|
|
|
// Get completed documents from legal team
|
|
const legalResponse = await fetch('https://app.documenso.com/api/v2/envelope?type=DOCUMENT&status=COMPLETED', {
|
|
headers: { Authorization: LEGAL_TEAM_TOKEN },
|
|
});
|
|
const legalDocs = await legalResponse.json();
|
|
|
|
console.log(`Sales team: ${salesDocs.count} pending`);
|
|
console.log(`Legal team: ${legalDocs.count} completed`);
|
|
```
|
|
|
|
## Error Responses
|
|
|
|
| Status | Description |
|
|
| ------ | ------------------------------------------------- |
|
|
| `401` | Invalid or expired API token |
|
|
| `403` | Token doesn't have permission for this operation |
|
|
| `404` | Resource not found or not accessible by this team |
|
|
|
|
### Example Error Response
|
|
|
|
```json
|
|
{
|
|
"message": "You do not have permission to access this resource"
|
|
}
|
|
```
|
|
|
|
<Callout type="warn">
|
|
API tokens can only access resources belonging to their associated team. Attempting to access
|
|
resources from another team returns a 403 or 404 error.
|
|
</Callout>
|
|
|
|
## See Also
|
|
|
|
- [Documents API](/docs/developers/api/documents) - Create and manage documents
|
|
- [Templates API](/docs/developers/api/templates) - Work with document templates
|
|
- [Authentication](/docs/developers/getting-started/authentication) - Create and manage API tokens
|