I’m having trouble with my ExactOnline API integration script. It works perfectly when I test it on my local machine, but breaks when I deploy it to automation platforms like Zapier or n8n. The script stops executing right before making HTTP requests.
Here’s my current implementation:
const apiToken = 'your_token_here';
const companyDivision = 'division_id';
const customerInfo = {
"Name": "business name",
"City": "location",
"Website": "example.com"
};
const personInfo = {
"FirstName": "john",
"LastName": "doe",
"City": "location name"
};
async function processAction(actionType) {
if (actionType == "create_customer_and_contact") {
const customerResult = await createCustomer(customerInfo);
const customerId = customerResult;
personInfo.Account = customerId;
const contactResult = await createPerson(personInfo);
return 'Operation completed successfully';
}
async function createCustomer(data) {
const result = await makePostRequest(1, data);
return result.d.ID;
}
async function createPerson(data) {
const result = await makePostRequest(2, data);
const updateData = {
MainContact: result.d.ID
};
await updateCustomer(updateData, data.Account);
return result.d.ID;
}
async function makePostRequest(requestType, payload) {
let apiUrl = `https://start.exactonline.nl/api/v1/${companyDivision}/crm/`;
if (requestType == 1) {
apiUrl += 'Accounts';
} else if (requestType == 2) {
apiUrl += 'Contacts';
}
const response = await fetch(apiUrl, {
method: "POST",
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer ' + apiToken,
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
return await response.json();
}
async function updateCustomer(updatePayload, recordId) {
const updateUrl = `https://start.exactonline.nl/api/v1/${companyDivision}/crm/Accounts(guid'${recordId}')`;
await fetch(updateUrl, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + apiToken
},
body: JSON.stringify(updatePayload)
});
}
}
async function executeMain() {
await processAction("create_customer_and_contact");
return "Process finished";
}
return executeMain();
Has anyone experienced similar issues with multiple API calls on these platforms? Any suggestions would be appreciated.