Update incident state from Resolved to New using REST API

Tony Sumy
Kilo Explorer

I am able to convert incident state from New to Resolved using REST API with following payload in python

payload = {'incident_state': 6, 'close_code': 'Closed/Resolved By Caller', 'close_notes': 'Request from API'}
response = requests.put('https://devxxxx.service-now.com/api/now/table/incident/31636d24db123300680453184b961990', json=payload)

Now I need to convert the same back to New 

payload = {'incident_state': 1, 'close_code': 'Closed/Resolved By Caller', 'close_notes': 'Request from API'}
response = requests.put('https://devxxxx.service-now.com/api/now/table/incident/31636d24db123300680453184b961990', json=payload)

On both the cases, I'm passing 'close_code' and 'close_notes'. Even though when I request to convert status from Resolved to New, I got response with error code 403 with the below error message 

{"error":{"message":"Operation Failed","detail":"Data Policy Exception: \\n\\tThe following fields are mandatory: Resolution code, Close notes"},"status":"failure"}

Let me know what I am doing wrong when sending request.

2 REPLIES 2

zift
Kilo Contributor

I literally just had this very same issue. I'm not sure which version of Service Now you are using, but in New York, there are certain integer values that I have found do not work. The default state of a newly opened incident is "In progress". Although "New" is an option in the drop down menu, if you actually select it, and save the incident, it still goes back to "In progress".  From trial and error, I have found the following state values to correspond to the following integers:

"In Progress" = 'state':'2'

"On Hold" = 'state':'3' (need to provide on hold reason and additional comments ('hold reason':int, 'comments': str)

"Resolved" = 'state':'6' (need to provide resolution code and close notes ("close_code":str,"close_notes":str)

"Closed" = 'state':'7' (need to provide resolution code and close notes ("close_code":str,"close_notes":str)
State codes 1,4, and 5, return status codes of 200 but do nothing in my experience.

Also, in my testing, "state" and "incident_state" appear to be interchangeable. Updating "state" updates "incident_state" and vice versa. Looks like what you need to do is change the integer from '1' to '2' and that should solve your issue. Hope this helps!   EDIT: I was wrong. "incident_state" and "state" are not interchangeable. You are using "incident_state" in your code. If you change it to "state", it will work without giving you those errors.

Michael George
Tera Guru

In case it helps someone in the future:
In my case, I was setting the "active" property to false, which was what was responsible for the mandatory values. I was creating a new record on the table and simply forgot to change it from the default value in my object.