Rest API Update Incident Status

jaypman
Kilo Contributor

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);

}

11 REPLIES 11

poornachander
Mega Expert

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' }


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  


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.


Thanks!