Rest API Update Incident Status
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2015 09:34 AM
I'm trying to update that status of an incident and was wondering if the rest call is correct? (using C# RestSharp)
public void UpdateIncidentStatus(string incidentNumber, string newStatus)
{
var request = new RestRequest("/api/now/table/incident?sysparm_query=number={incident_number}", Method.PUT) { RequestFormat = DataFormat.Json };
request.AddParameter("incident_number", incidentNumber, ParameterType.UrlSegment);
request.AddBody(new { status = newStatus }); // uses JsonSerializer
var response = client.Execute<RootObject>(request);
if (response.StatusCode == HttpStatusCode.NotFound)
throw new Exception(response.ErrorMessage);
}
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2015 07:28 AM
The REST request URL is wrong, remember you are not querying but modifying the existing record.
The URL should look like this: https://demo014.service-now.com/api/now/table/incident/<sysid>
<sysid> should be Incident Sys id
And the request body should be like this, if you follow JSON way, (here I have mentioned only incident state field, but can be any incident fields)
{'incident_state':'2',
'status' : 'Something' }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2015 07:33 AM
Thanks you for the quick response! Is there a way to update based on incident number instead of sys_id? I'm a bit new to REST so excuse my ignorance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2015 07:46 AM
Hypothetically, you could do a getRecords with that query, get the sys_id, throw it into a variable, pass that variable to the PUT, and then make your changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2015 07:49 AM
Thanks!