Thanks for looking…
Seems like a pretty common task but there isn’t much on the Post side for working examples floating about.
I’m not sure if my header is malformed or if I am doing something else basic wrong here.
working from the API Example for POST https://www.wix.com/corvid/reference/wix-fetch.html
I am seeing a warning:
"["Unhandled rejection TypeError: (intermediate value).catch is not a function
//Freshsales Example Account Post
curl -H "Authorization: Token token=sfg999666t673t7t82" -H "Content-Type: application/json" //-d '{"sales_account":{"name":"Widgetz.io (sample)"} }' -X POST "https://domain.freshsales.io/api/sales_accounts"
data.js
function updateFreshSales(item, context)
{
console.log('function updateFreshSales' );
const salesURL = 'https://domain.freshsales.io/api/sales_accounts';
// The data we are going to send in our request
let data = {
sales_account : {
name: item.companyName
}
};
JSON.stringify(data);
// The parameters we are going pass to the fetch function
fetch( salesURL, {
"method" : "post",
"headers": {
"Authorization": "Token token=N-dOp-iQLtl0JvwHTO67Sg",
"Content-Type": "application/json"
},
"body": data
})
.then( (httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject("Fetch did not succeed");
}
} )
.then( (json) => console.log(json.someKey) )
.catch(err => console.log(err))
}
export function partnerRequests_afterInsert(item, context) {
sendEmail(item, context);
updateFreshSales(item, context);
}