I've managed to interact with a database set up for testing purposes on Wix. I'm able to upload json data to it and I can see it in the LIVE database, albeit crudely. The issue is it just keeps inserting new rows/columns and I'm genuinely stump as to how I can get it to interact with existing fields.
Here's the Backend file code:
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("zpage_test", JSON.parse(body));
} )
.then( (results) => {
options.body = {
"inserted": results
};
return created(options);
} )
// something went wrong
.catch( (error) => {
options.body = {
"error": error
};
return serverError(options);
} );
}
Here's the VBA PUT code (..with Microsoft Scripting Runtime enabled in VBA references)
Sub SendJson()
Dim objHTTP As Object
Dim Json As String
Dim result As String
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
Url = "https://www.mywebsite.com/_functions/myFunction"
Json = "{""ID"":""d0f6f64a-e6d8-4cac-9285-d3e51bf3cb53"",""Title"":""tTitle1"",""t1"": ""1.5"", ""t2"": ""hello""}"
objHTTP.Open "PUT", Url, False
objHTTP.setRequestHeader "Content-type", "application/json"
objHTTP.Send (Json)
result = objHTTP.responseText
'Some simple debugging
Range("A15").Value = result
Range("D15").Value = Json
Set objHTTP = Nothing
End Sub
could some insight be provided as to whats failing here? I'd really appreciate your help!
Bookmarks