how to set up service now to allow pypy PySNC to red a table, the user can in the ui

DonaldI
Kilo Contributor

https://github.com/ServiceNow/PySNC/blob/main/docs/user/authentication.rst

 

from pysnc import ServiceNowClient
from pysnc.auth import ServiceNowPasswordGrantFlow
client_id = 'xxxxxxxxxxxxxxxx' # oauth_entity.client_id
secret = 'xxxxxxxxxxxxxxxx' # oauth_entity.client_secret
username = "xxxxxxxxxxxxxxxx" # your ServiceNow username
password = "xxxxxxxxxxxxxxxx" # your ServiceNow username and password
auth = ServiceNowPasswordGrantFlow(username, password, client_id, secret)
client = ServiceNowClient("https://aerosafedev.service-now.com/", auth, verify=False)
gr = client.GlideRecord('customer_account')
gr.add_query("active", "true")
gr.query()

for r in gr:
print(r)





The error message pysnc.exceptions.RoleException: {'error': {'message': 'User Not Authorized', 'detail': 'Access to unscoped api is not allowed'}, 'status': 'failure'} is the key. While you can see the table when logged into the ServiceNow application, API access is controlled separately and often requires specific permissions.
The detail "Access to unscoped api is not allowed" strongly suggests that the OAuth application you are using for authentication within ServiceNow is not configured to allow this type of API access for your user.
To fix this, a ServiceNow administrator needs to review the configuration of the OAuth application associated with the client_id used in the script. Specifically, they should check the "Allow access to this application scope from all application scopes" setting for the API that pysnc is trying to use.
This is a configuration change that must be made within your ServiceNow environment and cannot be resolved from the Python script itself. Once the ServiceNow administrator adjusts the permissions for the OAuth application or your user's roles for API access, the script should be able to execute the query successfully.

 

0 REPLIES 0