- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 11:22 AM
Hello ServiceNow Guru's,
I am trying to update a field in cmdb_ci_win_server using python REST API. I get the above error.
We have a custom field called "u_regulatory" in cmdb_ci_win_server table which references another table called u_choice_list_rc. sox_pci_sys_id references the ID of the field
Here is my code. Any what I am doing wrong here ?
sys_id = '3255f17cdb67938846577165ca9619d4' # Extracted from cmdb_ci_win_server
sox_pci_sys_id = '57b0ccc8dbd65b804c04f5361d9619e6' # Extracted from u_choice_list_rc
url = "https://vistra.service-now.com/api/now/table/{0}/{1}".format(cmdb_ci_win_server, sys_id)
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
payload = """{'%s' : '%s'}""" % ('u_regulatory',sox_pci_sys_id)
response = requests.put(url, auth=(user, pwd), headers=headers, json=payload)
print(response.text)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2019 10:09 PM
Figured it out myself after trial and error. It seems it doesn't like the payload. After I changed it like below and it worked fine.
payload = {'%s' % 'u_regulatory' : '%s' % str(sox_pci_sys_id)}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 11:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2019 10:09 PM
Figured it out myself after trial and error. It seems it doesn't like the payload. After I changed it like below and it worked fine.
payload = {'%s' % 'u_regulatory' : '%s' % str(sox_pci_sys_id)}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2020 11:06 AM
If you still need an example check this out created in Python
The main problem here is that your data that needs to be passed has to be in the perfect JSON format. If you have the single quote (') instead of double (") it will fail. So which every language you are using ensure that you have double quote around each piece of data.
x=1
y="Some Text" #Does not matter if you put single or double quote, python always takes single quote
response = requests.post(url, auth=(user, pwd), headers=headers ,data='{\"First_data\":\"'+x+'\",\"Second_data\":\"'+y+'\"}')
As you can see using backslash i have got the double quote added to the string and this string when generated becomes a proper JSON which ServiceNow accepts.
In case you are still getting some odd error on this line, critically check the sequence of quotes and the string concatenation. if the data that is being passed has any special characters then use the following site to check what they need to be replaced with. https://jsonformatter.curiousconcept.com/#