Hi
I am trying to do a view based PUT, however I can get the put to work in Postman. I have then copied the code over and changed my variables. It will not work in Knack. Below you will see the postman generated code then below that you will see the the code that I am using:
var settings = {
"url": "https://api.knack.com/v2/pages/scene_1254/views/view_2887/records/63eca91a59b6a900291827bc/",
"method": "PUT",
"timeout": 0,
"headers": {
"X-Knack-Application-Id": "640d9e616f3b35002a6bc541",
"X-Knack-REST-API-Key": "knack",
"Content-Type": "application/json",
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNjFlN2YyMjU4NjBlMjYwNzUzY2U3NjkIiwiYXBwbGljYXRpb25faWQiOiI2NDBkOWU2MTZmM2IzNTAwMmE2YmM1NDEiLCJpYXQiOjE2Nzg3MDMxNjN9.kXJWOFsdn8Y8rdA1D5XlPJ0XcbxzDCS7djNFMuQJXOE",
//I have changed the Auth code so that this can't be used
},
"data": JSON.stringify({
"field_5389": "Secondary"
}),
};
$.ajax(settings).done(function (response) {
console.log(response);
});
function putValuesInTable(sceneID, viewID, fieldID, inputVal) {
// var data = { 'field_5389': inputVal}
Knack.showSpinner();
// Prepare filters
var settings = {
"url": `https://api.knack.com/v1/pages/scene_${sceneID}/views/view_${viewID}/records/${getRecordID()}/`,
"method": "PUT",
"timeout": 0,
"headers": {
"X-Knack-Application-Id": Knack.application_id,
"X-Knack-REST-API-Key": "knack",
"Content-Type": "application/json",
"Authorization": Knack.getUserToken(),
},
"data": JSON.stringify({
"field_5389": "Secondary"
}),
};
return new Promise(function (resolve, reject) {
$.ajax(settings)
.done(function (data) {
console.log(data);
// console.log(response);
Knack.hideSpinner();
resolve(data);
})
.fail(function (error) {
console.log('Error');
Knack.hideSpinner();
reject(error);
});
});
}
If anyone can help this would be really appreciated. I have been searching for hours and as far as I can tell this is how it should be done.
p.s. I am not using the variables for the data yet as I am testing.
Update: I have managed to get this to work in JavaScript using the code snippet from Postmen. I mainly use Jquery though and would appreciate any help someone can give me.