I’m having trouble with my ExactOnline API integration script. It works perfectly when I test it on my local machine, but fails when I deploy it to automation platforms like Zapier or n8n. The script seems to stop executing right before making fetch requests.
Here’s a simplified version of my automation code:
const apiToken = 'your_api_token';
const companyId = 'your_company_id';
const customerInfo = {
"Name": "Test Company",
"City": "New York",
"Website": "example.com"
};
const personInfo = {
"FirstName": "John",
"LastName": "Smith",
"City": "New York"
};
async function processData(operation) {
if (operation === "create_customer_and_contact") {
const customerId = await createCustomer(customerInfo);
personInfo.Account = customerId;
const contactId = await createContact(personInfo);
return 'Process completed successfully';
}
}
async function createCustomer(data) {
const result = await makePostRequest(1, data);
return result.d.ID;
}
async function createContact(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/${companyId}/crm/`;
apiUrl += requestType === 1 ? 'Accounts' : '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(data, customerId) {
const updateUrl = `https://start.exactonline.nl/api/v1/${companyId}/crm/Accounts(guid'${customerId}')`;
await fetch(updateUrl, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiToken}`
},
body: JSON.stringify(data)
});
}
async function main() {
return await processData("create_customer_and_contact");
}
output = [main()];
Any ideas why this might be happening on these platforms but not locally?