Neidio i’r prif gynnwys

Anfon Dogfen

Yn y cam hwn byddwch yn defnyddio'r mutation send i anfon dogfen i'w llofnodi. Dyma'r gweithred fwyaf cyffredin yn API Legalesign.

Gofynion Rhagofynol

Mae angen:

Gallwch ddod o hyd i'r ddau drwy holi eich grwpiau a'u templedi — gweler y cam blaenorol.

Anfon y ddogfen

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);

Os ydych am gynnwys roleId, holwch rolau'r templed gyda template { roles { id signerIndex } } (gweler y cam blaenorol).

Os yw'r mewnbwn yn annilys, mae'r mutation yn dychwelyd gwall ar unwaith.

Os yw'r mutation yn llwyddo, mae'n dychwelyd ID tasg. Mae'r ddogfen yn cael ei phrosesu'n asyncronig.

Gwiriwch statws y dasg

Holwch ymholiad y tasg i wirio pryd mae'r anfon wedi cwblhau:

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));

Archwiliwch status.data.task.report?.status yn eich cleient. Pan ddaw'n COMPLETED, mae creu'r ddogfen wedi gorffen. Os ddaw'n FAILED, nid oedd yr anfon wedi cwblhau'n llwyddiannus.

Enghraifft gyflawn sy'n gweithio

Dyma'r index.js cyflawn yn cyfuno pob cam:

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);

Camau nesaf

Export This Article

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