Creating approval for a specific incident using REST api in Python.

Ibrahim10
Kilo Explorer

Hi,

i have a use case where i need to create the approval for a specific incident programatically.

i am trying to do this using the REST Api in python by following code snippet:

import requests
import json

user='admin'
pwd=''

url='https://dev68600.service-now.com/api/now/table/sysapproval_approver'
headers = {"Accept":"application/json"}


mydata={'state':'Not yet Requested',"approver":"971e029d983500107f2c2ed01a1f167d","source_table":"incident","sysapproval":'73908958dbf51010aa4df53a29961918','docuemnt_id':"73908958dbf51010aa4df53a29961918"}
response = requests.post(url, auth=(user, pwd), headers=headers ,data=json.dumps(mydata))

With the above i am able to create a record in the approval table but having the following problems:

  1. not able to add the approver by adding sys_id/user_id from the users table?
  2. not able to link this approval to the incident record i wanted to?

i have attached the images for the created records in the approval table.

find_real_file.png

find_real_file.png

in the above image linked incident is not the one for which i provided sys_id in my_data and passed as parameters.

Please help me in this problem.

Thanks for your time.

Regards

6 REPLIES 6

Hitoshi Ozawa
Giga Sage
Giga Sage

So is your question to short that columns "approver" and "Approval for" are not being inserted into the record?

Variable name of "approver" is "approver" and is a reference to User table.

Variable name of "Approval for" is "sysapproval" and is a reference to Task table.

yes thats exactly its short version is.

so for the approver reference would be the sys_id for that specific user from the user table.

and for sysapproval Task table can be incident,request item or similar kind of tables right?

 

Hitoshi Ozawa
Giga Sage
Giga Sage

Seems similar to the following threads.

https://community.servicenow.com/community?id=community_question&sys_id=1522eea8dbac5050190dfb24399619a4

https://community.servicenow.com/community?id=community_question&sys_id=2bc00176db271fc4a39a0b55ca961958

 

thanks for the references i couldnt find before..

i have gone through these threads and need to clarify the following things:

  • is this possible through REST Api using /api/now/table/sysapproval_approver namespace? if no whats the alternate we can use in python? as in the above mentioned thread the guy mentioned that he couldnt do it with /now namesapce but can do through the scripted REST Api... which one is that we can use in Python ?
  • to create an approval for a record from incident table, i have the record already created in the incident table, user who is going to be approver is already there in User table... do we need to do anything else before creating an approval in sysapproval_approver table?

appreciate the help.

 

Regards