Created
July 29, 2024 15:04
-
-
Save cfjedimaster/1e26caca39351b0d6c8dc902028360b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This is hard coded, but in a real application would be dynamic: | |
*/ | |
let email = '[email protected]'; | |
async function documentGenerationJob(asset, outputFormat, data, token, clientId) { | |
let body = { | |
'assetID': asset.assetID, | |
'outputFormat': outputFormat, | |
'jsonDataForMerge':data | |
}; | |
let resp = await fetch(REST_API + 'operation/documentgeneration', { | |
method: 'POST', | |
headers: { | |
'Authorization':`Bearer ${token}`, | |
'X-API-KEY':clientId, | |
'Content-Type':'application/json' | |
}, | |
body:JSON.stringify(body) | |
}); | |
return resp.headers.get('location'); | |
} | |
let docGenAsset = await getUploadData('application/vnd.openxmlformats-officedocument.wordprocessingml.document', accessToken, CLIENT_ID); | |
await uploadFile(docGenAsset.uploadUri, WATERMARK_DOC,'application/vnd.openxmlformats-officedocument.wordprocessingml.document'); | |
console.log('Source Word doc Uploaded'); | |
let job = await documentGenerationJob(docGenAsset, 'pdf', { email }, accessToken, CLIENT_ID); | |
console.log('Generating new PDF'); | |
let docgenResult = await pollJob(job, accessToken, CLIENT_ID); | |
console.log('Document generation job done'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment