Hi Wix Coders,
Noting following …
- Collection permissions - All set to Anyone except Delete (Admin only)
- Confirm able to update Collection using https://support.wix.com/en/article/how-to-import-and-export-collection-data-using-the-wix-data-api
… i.e. assume Collection permissions are acceptable for external update.
Now trying POST option from https://support.wix.com/en/article/exposing-a-site-api-with-http-functions ;
Backend http-functions.js contains;
export function post_myFunction(request) {
let options = {
“headers”: {
“Content-Type”: “application/json”
}
};
// get the request body
return request.body.text()
.then( (body) => {
// insert the item in a collection
return wixData.insert(“CntrRetCollection”, JSON.parse(body));
} )
.then( (results) => {
options.body = {
“inserted”: results
};
return created(options);
} )
// something went wrong
. catch ( (error) => {
options.body = {
“error”: error
};
return serverError(options);
} );
}
JSON looks like (i.e. same format as update exercise above) …
[
{
“containerNumber”: “ABCD5566778”,
“returnLocation”: “LVL 3, 111 ABC ST, SYD”
},
{
“containerNumber”: “DEFG6677889”,
“returnLocation”: “LVL 3, 111 ABC ST, SYD”
}
]
… and we’re using Excel 2016 VBA (Microsoft Scripting Runtime enabled in VBA references) to send the JSON string;
Sub SendJson()
Dim objHTTP As Object
Dim Json As String
Json = Range(“A5”)
Dim result As String
Set objHTTP = CreateObject(“MSXML2.XMLHTTP”)
'Set objHTTP = CreateObject(“MSXML2.ServerXMLHTTP”)
Url = " https://oalbps.wixsite.com/cret/_functions/myFunction "
objHTTP.Open “POST”, Url, False
objHTTP.setRequestHeader “Content-type”, “application/json”
objHTTP.Send (Json)
result = objHTTP.responseText
'Some simple debugging
Range(“A25”).Value = result
Range(“A26”).Value = Json
Set objHTTP = Nothing
End Sub
… but getting following error in Excel cell A25;
{“error”:{“code”:“WD_VALIDATION_ERROR”}}
Any clues on cause of this error? Are SSL certificates or API tokens required or is error due to some data format error?
Thanks.