Not so much ideas as more questions.
wix-fetch seems to generate different output than is expected.
For example I am working on getting this curl statement to work.
(the curl command creates an account successfully on the target server.)
curl -H “Authorization: Token token=R0DnotmykeyFQ” -H “Content-Type: application/json” -d ‘{“sales_account”:{“name”:“Account test”} }’ -X POST “https://ucworkspace.freshsales.io/api/sales_accounts”
When I use a this nice little curl to fetch utility to generate a valid fetch statement: https://kigiri.github.io/fetch/
I get this.
fetch("https://ucworkspace.freshsales.io/api/sales_accounts", {
body: "{\"sales_account\":{\"name\":\"Account test\"} }",
headers: {
Authorization: "Token token=R0DTvnotmykeyPSOBIhFQ",
"Content-Type": "application/json"
},
method: "POST"
})
Then when I put it in the back-end, and add some instrumentation to it I get a
httpResponse.statusText of “Bad Request”
either trivially with no instrumentation
data.js
import {fetch} from 'wix-fetch';
function updateFreshSales(item, context)
{
fetch("https://ucworkspace.freshsales.io/api/sales_accounts", {
body: "{\"sales_account\":{\"name\":\"Account test\"} }",
headers: {
Authorization: "Token token=R0DTvwXvtnotmykeyhPSOBIhFQ",
"Content-Type": "application/json"
},
method: "POST"
});
}
or
with error checking
data.js
import {fetch} from'wix-fetch';
function updateFreshSales(item, context)
{
console.log('function updateFreshSales' ); fetch("https://ucworkspace.freshsales.io/api/sales_accounts", {
body: "{\"sales_account\":{\"name\":\"Account test\"} }",
headers: {
Authorization: "Token token=R0DTvbnotmykeyBIhFQ",
"Content-Type": "application/json"
},
method: "POST"
})
.then( (httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
console.log("Status: " + httpResponse.statusText);
return Promise.reject("Fetch did not succeed");
}
} )
.then( (json) => console.log(JSON.stringify(json)) )
.catch(err => console.log(err))
}
The big question I have is wtf is WIX fetch sending? How do we dump the request itself to see what is wrong and work around it? wix-fetch is obviously not as robust as normal fetch but figuring out how so that we can form a valid request seems to be unusually painful.