I am trying to post json data from an automation tool. I have created a file in wix code in the backend titled http-functions.js with the follow code.
import {created, serverError} from ‘wix-http-functions’;
import wixData from ‘wix-data’;
// URL looks like:
// https://mysite.com/_functions/myFunction/
// or:
// https://user.wixsite.com/mysite/_functions/myFunction/
export function post_myFunction(request) {
let options = {
“headers”: {
“Content-Type”: “application/json”
}
};
// get the request body
return request.body.json()
.then( (body) => {
// insert the item in a collection
return wixData.insert(“PAData”, body);
} )
.then( (results) => {
options.body = {
“results”: results
};
return created(options);
} )
// something went wrong
.catch( (error) => {
options.body = {
“error”: error
};
return serverError(options);
} );
}
I am trying to write an array to my PAData collection with a Invoke Web Service module in my automation program. The array as follows:
{“PAData”:[
{"title":"test"},
{"paOwner":"Test"},
{"address": "123test"},
{"parcelId": "1235"},
{"paLegal": Lot 21 Test"},
]}
I would appreciate any help. I have been struggling with this for a week and can not figure out what is going wrong. I believe I am reaching the server, but getting error 500 code returned. Not sure if I should be authenticating or what. I am not finding detailed information on how to post data directly to a collection not using a form. Thanks all.