I’m having trouble with my ExactOnline API integration. My script works perfectly when I test it on my local machine, but it breaks when I deploy it to automation platforms like Zapier or n8n. The issue seems to happen right before making fetch requests.
const authToken = 'your-token-here';
const companyId = 'division-id';
const clientInfo = {
"CompanyName": "sample company",
"Location": "sample city",
"WebAddress": "example.com"
};
const personInfo = {
"GivenName": "john",
"FamilyName": "doe",
"Location": "sample city"
};
async function processRequest(requestType) {
if (requestType == "create_client_and_person") {
const clientResult = await createClient(clientInfo);
const clientGUID = clientResult;
personInfo.ClientAccount = clientGUID;
const personResult = await createPerson(personInfo);
return 'Process completed successfully';
}
}
async function createClient(data) {
const response = await sendPOST(1, data);
return response.d.ID;
}
async function createPerson(data) {
const response = await sendPOST(2, data);
const updateData = {
PrimaryContact: response.d.ID
};
await updateClient(updateData, data.ClientAccount);
return response.d.ID;
}
async function sendPOST(entityType, payload) {
let apiUrl = `https://start.exactonline.nl/api/v1/${companyId}/crm/`;
apiUrl += entityType === 1 ? 'Accounts' : 'Contacts';
const response = await fetch(apiUrl, {
method: "POST",
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${authToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
return await response.json();
}
Anyone else run into this problem with ExactOnline API calls on these platforms?