I’m attempting to post data using a REST service. I can make it work in Postman, but need help with the Javascript. Essentially, I want it to find a record (objectId) and update its attributes. I’m fairly certain I have the json array formatted incorrectly in the Javascript. Any help is appreciated!
Backend:
import { fetch } from ‘wix-fetch’;
export function EditAttributes() {
return fetch(“Insert ServiceURL+Token Here”, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’
},
body: JSON.stringify({
attributes: {
objectId: 3,
FacilityName: ‘Rocky’,
ShellApproved: ‘Yes’,
P66Approved: ‘Yes’,
Address: ‘Gettysburg’,
Phone: ‘1-800-123-4567’,
email: ‘test@test.com’,
WasteAccepted: ‘Haz’,
ID: ‘3’
}
})
}).then((httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject(“Fetch did not succeed”);
}
});
}
Frontend → just a button to trigger the backend for now:
import {EditAttributes} from ‘backend/EditAttributes’;
export function button1_click(event) {
EditAttributes()
.then(httpResponse => {
console.log(httpResponse);
})
. catch (error => {
console.log(error);
});
}
I get this error: