Send a Document
In this step you'll use the send mutation to send a document for signing. This is the most common operation in the Legalesign API.
Prerequisites
You need:
- A token or API key from Authenticate with the API
- The
graphqlhelper from the GraphQL Quickstart - A group ID — the team the document belongs to
- A template ID — the PDF template to send
You can find both by querying your groups and their templates — see the previous step.
Send the document
const sendResult = await graphql(token, `
mutation SendDocument($input: DocumentSendSettingsInput!) {
send(input: $input)
}
`, {
input: {
groupId: '<your-group-id>',
templateId: '<your-template-id>',
title: 'Test Document',
recipients: [
{
firstName: 'Jane',
lastName: 'Smith',
email: 'jane@example.com',
order: 0
}
]
}
});
console.log('Task ID:', sendResult.data.send);
If you want to include roleId, query the template's roles with template { roles { id signerIndex } } (see the previous step).
If the input is invalid, the mutation returns an error immediately.
If the mutation succeeds, it returns a task ID. The document is processed asynchronously.
Check the task status
Poll the task query to check when sending is complete:
const taskId = sendResult.data.send;
const status = await graphql(token, `
query CheckTask($id: ID!) {
task(id: $id) {
data
report {
status
batchId
documents
errors
}
}
}
`, { id: taskId });
console.log(JSON.stringify(status, null, 2));
Inspect status.data.task.report?.status in your client. When it becomes COMPLETED, document creation has finished. If it becomes FAILED, the send did not complete successfully.
Full working example
Here's the complete index.js combining all steps:
const GRAPHQL_ENDPOINT = 'https://graphql.uk.legalesign.com/graphql';
const TOKEN = '<token-or-api-key>';
async function graphql(token, query, variables = {}) {
const response = await fetch(GRAPHQL_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({ query, variables })
});
const result = await response.json();
if (result.errors) console.error('GraphQL errors:', result.errors);
return result;
}
async function main() {
const result = await graphql(TOKEN, `
mutation SendDocument($input: DocumentSendSettingsInput!) {
send(input: $input)
}
`, {
input: {
groupId: '<your-group-id>',
templateId: '<your-template-id>',
title: 'Test Document',
recipients: [
{
firstName: 'Jane',
lastName: 'Smith',
email: 'jane@example.com',
order: 0
}
]
}
});
console.log('Task ID:', result.data.send);
}
main().catch(console.error);
Next steps
- Add more options to your send — see DocumentSendSettingsInput for all available fields
- Send to multiple recipients or in sequence — see sending methods explained
- Send many documents at once — see sendBatch and sendBulk
- Browse more mutation examples