I have a script that handles customer creation and updates using the ExactOnline API. The script works perfectly when I test it locally, but when I deploy it to automation platforms like Zapier or n8n, it stops working properly.
On Zapier, the execution halts right before making the fetch request. Here’s my implementation:
var authToken = 'bearer_token_here';
var companyDivision = 'division_id_here';
var customerInfo = {
"Name": "business name",
"City": "location",
"Website": "example.com"
};
var personInfo = {
"FirstName": "john",
"LastName": "doe",
"City": "hometown"
};
var resultCustomerId;
async function processAction(actionType) {
var currentAction = actionType;
if (currentAction == "create_customer_and_contact") {
var newCustomerResult = await createCustomer(customerInfo);
var customerGuid = newCustomerResult;
personInfo.Account = customerGuid;
var newPersonResult = await createPerson(personInfo);
var personGuid = newPersonResult;
resultCustomerId = customerGuid;
return ('contact creation successful');
}
async function createCustomer(customerData) {
console.log('creating customer: ');
var customerResponse = await makePostRequest(1, customerData);
console.log('customer created: ' + JSON.stringify(customerResponse));
return await customerResponse.d.ID;
}
async function createPerson(personData) {
var personResponse = await makePostRequest(2, personData);
console.log('person created: ' + JSON.stringify(personResponse));
var updateData = {
MainContact: personResponse.d.ID
};
var targetCustomerId = personData.Account;
await modifyCustomer(updateData, targetCustomerId);
}
async function makePostRequest(requestType, payload) {
console.log('making post request');
var apiUrl = 'https://start.exactonline.nl/api/v1/' + companyDivision + '/crm/';
if (requestType == 1) {
apiUrl += 'Accounts';
}
if (requestType == 2) {
apiUrl += 'Contacts';
}
var result;
await fetch(apiUrl, {
method: "POST",
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer ' + authToken,
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
}).then(response => {
return response.json();
}).then(jsonData => {
result = jsonData;
}).catch(error => {
console.log(error);
});
return result;
}
async function modifyCustomer(updatePayload, customerId) {
var updateUrl = 'https://start.exactonline.nl/api/v1/' + companyDivision + '/crm/';
updateUrl += "Accounts(guid'" + customerId + "')";
await fetch(updateUrl, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + authToken
},
body: JSON.stringify(updatePayload)
});
}
}
async function executeProcess() {
console.log("starting process");
await processAction("create_customer_and_contact");
return ("process completed");
};
output = [executeProcess()]
Has anyone encountered similar issues with ExactOnline API calls on these platforms? What could be causing the difference in behavior between local and cloud execution?