Hello Gentlemen, I hope you are doing well. I am working on a project where I need to connect our CRM (Tape) to a digital signature platform. I would like some help to understand where I might be going wrong in constructing the code for sending client data and the contract via API. In my scenario, I have to use GraphQL in the code to be able to create the file on the signature platform. Can you help me by validating the code and pointing out possible corrections? Regards
import 'whatwg-fetch';
function downloadFileAndConvertToBase64(url: string): Promise<string> {
return fetch(url)
.then(response => response.blob())
.then(blob => new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result as string);
reader.onerror = reject;
reader.readAsDataURL(blob);
}));
}
const mutation = `
mutation CreateDocumentMutation(
$document: DocumentInput!,
$signers: [SignerInput!]!,
$file: Upload!,
$organization_id: Int
) {
createDocument(
document: $document,
signers: $signers,
file: $file,
organization_id: $organization_id
) {
id
name
refusable
sortable
created_at
signatures {
public_id
name
email
created_at
action { name }
link { short_link }
user { id name email }
}
}
}
`;
const url = contrato_field_files_file_url
downloadFileAndConvertToBase64(url).then(base64String => {
const data = JSON.stringify({
query: mutation,
variables: {
document: {
name: contrato_field_files_filename,
},
signers: [
{ email: "xx@dat4force.com.br", action: "SIGN" },
{ email: "xx@outlook.com.br", action: "SIGN" }
],
file: base64String
}
});
fetch('https://api.autentique.com.br/v2/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
},
body: data
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Erro na requisição:', error));
});