Example: Create document
This example demonstrates how the Kameleon API can be used to create single document from document template.
Node.js + TypeScript
Following environment variables are used in example
TENANT_ID,CLIENT_IDandCLIENT_SECRETAzure AD credentials used for authentication.API_URLhttps://api.kameleon.appAPI_SCOPEscope for Kameleon APIapi://e95a233a-a13e-4c5d-99b9-51832e41e036/.defaultAUTHOR_NAMEname of the document author e.g John DoeCOMPANY_IDcompany identifier retrieved from the Kameleon API.UNIT_IDcompany unit identifier retrieved from the Kameleon API.DOCUMENT_IDdocument template identified retrieved from the Kameleon API
Full example
This example uses client secret to acquire access token for Kameleon API call.
import { ClientSecretCredential } from "@azure/identity";
async function createDocument() {
const { TENANT_ID, CLIENT_ID, CLIENT_SECRET, API_SCOPE } = process.env
const credential = new ClientSecretCredential(TENANT_ID!, CLIENT_ID!, CLIENT_SECRET!)
const accessToken = await credential.getToken(API_SCOPE!)
const { API_URL, DOCUMENT_ID, AUTHOR_NAME, COMPANY_ID, UNIT_ID } = process.env
const url = new URL(`/v1.0/documents/${DOCUMENT_ID}/create`, API_URL)
const response = await fetch(url, {
headers: {
'Content-Type': 'application/json',
'Authorization': `${accessToken.tokenType} ${accessToken.token}`
},
method: 'POST',
body: JSON.stringify({
author: {
name: AUTHOR_NAME,
companyId: COMPANY_ID,
unitId: UNIT_ID
},
properties: {}
})
})
await response.bytes() // Document binary, could be e.g. saved to external system
}
createDocument()