Authentication failure when trying to insert a record to a table using table API (/api/now/table/{tableName}).

Nrupan Satheesh
Giga Contributor
I am trying to insert a record to a table using table API (/api/now/table/{tableName}). 
 
This is the code I have used exactly like given in the developer.servicenow.com. But I am getting an error in response saying  {'error': {'detail': 'Required to provide Auth information', 'message': 'User Not Authenticated'}, 'status': 'failure'} , Although I have provided username and password in the request  as shown below.
Note: I am able to create record in this table manually through now platform.
 
import requests
import json
 
url = "https://*****************.service-now.com/api/now/table/core_company"
user ="**********"
pwd= "*************"
 
headers = {
  'Accept': 'application/json',
  'Content-Type': 'application/json',
}
response = requests.post(url, auth=(user, pwd), headers=headers, data="<request><entry><name>{}</name></entry></request>".format("AXA"))
 
if response.status_code != 201:
    print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:', response.json())
    exit()
 
data = response.json()
print(data)
 
 
1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

HI,

have you provided to user these roles 

1. rest_service

2. web_service_admin

If not lets give these roles and try again.

 

Thanks,

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

8 REPLIES 8

SumanthDosapati
Mega Sage
Mega Sage

Hi,

Check if the username and password are correct. Are you able to use those credentials to login?

 

Regards,
Sumanth

Yes,
I am able to login using the exact credentials used in the script

It is Working now
Thanks sumanth

 

Pavankumar_1
Mega Patron

HI,

have you provided to user these roles 

1. rest_service

2. web_service_admin

If not lets give these roles and try again.

 

Thanks,

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar