I have a script that handles creating and updating records through the ExactOnline API. Everything works perfectly when I test it on my local machine, but when I deploy it to automation platforms like Zapier or n8n, it stops working properly.
const authToken = 'my_token_here';
const companyDivision = 'division_id_here';
const companyInfo = {
"Name": "business name",
"City": "location",
"Website": "example.com"
};
const personDetails = {
"FirstName": "john",
"LastName": "doe",
"City": "location name"
};
async function processRequest(requestType) {
if (requestType == "create_company_and_person") {
const companyResult = await createCompany(companyInfo);
const newCompanyId = companyResult;
personDetails.Account = newCompanyId;
const personResult = await createPerson(personDetails);
return 'Process completed successfully';
}
}
async function createCompany(data) {
const response = await sendPostRequest(1, data);
return response.d.ID;
}
async function createPerson(data) {
const response = await sendPostRequest(2, data);
const updateData = { MainContact: response.d.ID };
await updateCompany(updateData, data.Account);
return response.d.ID;
}
async function sendPostRequest(requestType, payload) {
let apiUrl = `https://start.exactonline.nl/api/v1/${companyDivision}/crm/`;
apiUrl += requestType === 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();
}
async function updateCompany(updateData, companyId) {
const updateUrl = `https://start.exactonline.nl/api/v1/${companyDivision}/crm/Accounts(guid'${companyId}')`;
await fetch(updateUrl, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authToken}`
},
body: JSON.stringify(updateData)
});
}
async function executeWorkflow() {
await processRequest("create_company_and_person");
return "Workflow completed";
}
output = [executeWorkflow()];
The issue seems to happen specifically when making multiple API calls in sequence. Has anyone experienced similar problems with ExactOnline API on these platforms?