Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Update incident in service now using Python

Piyush36
Kilo Explorer

Hi All,

I am trying to post worknotes(additional_comments) on an incident using below in a python script. I have tried the same with Request Item and was able to do so.

 

I have tried this with request item (sc_task)

def postComments(sctaskID, notes):
    uname, pwd = X,Y
    url = '{0}processRequestTask.do'.format(ServiceNowBaseURL)

    headers = {"Content-Type":"application/xml", "Accept":"application/xml"}
    content = "<request><task_id>" + sctaskID + "</task_id><additional_comments>"+ notes + "</additional_comments></request>"
    logging.info(content)
    r = requests.post(url, data=content, auth=(uname, pwd), headers=headers)
    
    responseCode = getResponseCode(r)
    if responseCode != "0": 
        logging.error(r.text)
        return None
    return "Success"

 

What will be used for incident (inplace of processRequestTask.do).. i have tried incident.do & processincident.do but it doesn't work.

Is there any way we can find what URL is used in service now to process an incident while doing an API call.

If I try: https://instance.service-now.com/incident.do --> it leads to create new incident page. I wish to update the additional comments in the incident.

Any help is greatly appreciated!! Thanks

5 REPLIES 5

AB3
Tera Expert

https://dev78987.service-now.com/api/now/table/incident/{sys_id}

Request Type: Post

Request Body:{"work_notes":"hello world"}

Headers:

Accept: application/json 

Content-Type: application/json
Authorization: Basic d3MuaHB1c25hOkRldjIwMjFAMTIzNA==
 
 
 
 May you find it helpful