Skip to main content

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:

You can find both by querying your groups and their templates — see the previous step.

Send the document

index.js
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:

index.js
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:

index.js
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

Export This Article

Save a copy of this page as PDF or plain text.