Leum gu prìomh susbaint

Cuir Sgrìobhainn air Chìs

Anns a’ cheum seo cleachdaidh tu am send mutation gus sgrìobhainn a chur airson soidhnigeadh. Is e seo an gnìomh as cumanta ann am MCP Legalesign.

Feumalachdan Ro-làimh

Tha feum agad air:

Faodaidh tu an dà chuid a lorg le bhith a’ dèanamh ceist air na buidhnean agad agus am teamplaidean aca — faic an ceum roimhe.

Cuir an sgrìobhainn air chùlaibh

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

Ma tha thu airson roleId a chur ris, dèan ceist air dreuchdan an teamplaid le template { roles { id signerIndex } } (faic an ceum roimhe).

Ma tha an sgrìobhainn inntrigidh ceàrr, thèid mearachd a thoirt chun àm sin.

Ma bhios am mutation soirbheachail, thèid ID tàsgaidh-obrach a thilleadh. Tha an sgrìobhainn air a lìonadh gu asyncrono.

Sgrùdaich suidheachadh an obair

Dèan sgrùdadh air a’ cheist task gus faicinn cuin a bhios an cur seachad deiseil:

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

Sgrùdaich status.data.task.report?.status anns a’ chliant agad. Nuair a thig e gu bhith COMPLETED, tha crìoch air cruthachadh na sgrìobhainn. Ma thig e gu bhith FAILED, cha do chrìochnaich an cur seachad gu soirbheachail.

Eisimpleir làn-obrach

Seo an index.js làn-obrach a’ cothlamadh na ceumannan gu lèir:

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

Na ceumannan a leanas

Export This Article

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