Discussion

Ask a Question
Back to All

Correct JSON format for setting the state field on an item

I am trying to change the state of a request through javascript (Google script to be exact) but it is not executing and I am assuming that it is how I am forming the payload or defining the EntityState Name value. I can use the same script to update custom fields with a different payload and that is why I am assuming the issue is with the format of the payload. Here is my code.

// sets the state in TP for the change on the spreadsheet.
function setState(TP, state) {
var payload = {
"EntityState" : {'Name': state}
};
var options = {
'method': 'POST',
'payload': JSON.stringify(payload),
'contentType' : 'application/json',
};

var TPid = TP.toString();
var token = "?&access_token=mytoken&format=json";
UrlFetchApp.fetch("https://kofile.tpondemand.com/api/v1/Requests/" + TPid + token, options);
}