Error Code 2001: Title cannot be empty

Hello, I’ve been implementing a create incident Rest API v2 call but the return is generating the following error. message:“Invalid Input Provided”, code:2001, errors:[“Title cannot be empty.”]

Here is my code in Google Apps Script, any help is appreciated!

var options = {
method: 'POST',
muteHttpExceptions: true,
headers: {
  'Authorization': 'Token token=<my token>',
  'Accept':'application/vnd.pagerduty+json;version=2',
  'From': '<my email>',
  'Content-Type': 'application/json'
},
"incident": {
  "type": "incident",
  "title": "Test Escalation",
  "service": {
    "id": "<our service id>",
    "type": "service_reference"
  }
}

};

var response = UrlFetchApp.fetch(‘https://api.pagerduty.com/incidents’, options);

var json = response.getContentText();
var responseData = JSON.parse(json);

Hello,

Check out the below which will help with the Google Apps script. But please do note it is not supported from our side –

function sendToPagerDuty(service_key) {
var url = “https://events.pagerduty.com/generic/2010-04-15/create_event.json”;
var data = {
“service_key”: service_key,
“event_type”: “trigger”,
“description”: “FAILURE for production/HTTP on machine srv01.acme.com”,
“client”: “Sample Monitoring Service”,
“client_url”: “https://monitoring.service.com”,
“details”: {
“ping time”: “1500ms”,
“load avg”: 0.75
},
“contexts”:[
{
“type”: “link”,
“href”: “http://xxxxx.pagerduty.com”,
“text”: “View the incident on PagerDuty”
},{
“type”: “image”,
“src”: “https://chart.googleapis.com/chart?chs=600x400&chd=t:6,2,9,5,2,5,7,4,8,2,1&cht=lc&chds=a&chxt=y&chm=D,0033FF,0,0,5,1
}
]
};
var payload = JSON.stringify(data);
var headers = {“Accept”:“application/json”,
“Content-Type”:“application/json”,
“Authorization”:“Basic authcode
};
var options = { “method” : “POST”,
“contentType” : “application/json”,
“headers” : headers,
“payload” : payload
};
try {
var response = UrlFetchApp.fetch(url, options);
var json = JSON.parse(response.getContentText());
Logger.log(“status:” + json.status + " message:" + json.message + " incident_key:" + json.incident_key);
} catch(e){
var error = e;
Logger.log(“message:” + error.message + “fileName:” + error.fileName + “nlineNumber:” + error.lineNumber + “nstack:” + error.stack);
}
}

Hope this helps!

Kind regards,
John