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

Hi 
I added these two roles, still the same result, not working

It is working now.
Thanks pavan

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

things to check

1) is the username password correct

2) does that API user has Table level CREATE Access or not

regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

It is working now
Thanks Ankur