Skip to main content

Google Script app code

function createTicket(e) {

var API_KEY='My API ';

var ENDPOINT = 'My domain'; // change to https if SSL is configured.

var headers = {
'Content-type': 'application/json',
'Authorization': 'Basic ' + Utilities.base64Encode(API_KEY + ':X')
};


var payload = JSON.stringify({
"description":"Help needed desparately",
"subject":"Testing API",
"email":"[email protected]",
"priority":1,
"status": 2 ,
/*I did try this didn't work either*/
// 'custom_field[cf_campus]':'QLD'
"custom_field":
{
"cf_campus": "QLD"

}
})



var url = ENDPOINT + '/api/v2/tickets';

var options = {
'method': 'post',
'headers': headers,
'payload': payload,
muteHttpExceptions: true
};
// Logger.log("url: " + url);
Logger.log("payload: " + options.payload);
Logger.log("headers: " + options.headers);
var response = UrlFetchApp.fetch(url, options);

Logger.log("code: " + response.getResponseCode());
Logger.log("text: " + response.getContentText());
}

/* Getting this error in output
code: 400
text: {"description":"Validation failed","errors":[{"field":"custom_field","message":"Unexpected/invalid field in request","code":"invalid_field"}]}
*/

getting error 400

text: {"description":"Validation failed","errors":[{"field":"custom_field","message":"Unexpected/invalid field in request","code":"invalid_field"}]}

All resolved.

I had to enter all custom_fields children even if they had a null value


Reply