generateAuth of SN_AUTH API throws exception for users other than System Admin.

DH7
Tera Contributor

We have built one custom scoped application in which we are fetching the data from the AWS SQS Queue using the REST MessageV2 API and SN_AUTH API

 

In order to fetch the data from the AWS SQS Queue, we will have to sign our request using the generateAuth() method of the sn_auth.RequestAuthAPI() API and make the REST call using the RESTMessageV2 API.

 

Now this works fine if the code is run by the ServiceNow System Admin, but when we try to run the code from our App admin, it's throwing the error "java.lang.NullPointerException".

 

Our App Admin has the following roles:
itil
itil_admin
sn_si.admin
flow_operator
workflow_admin
mid_server
sn_ti.malicious_attachment_access
sn_ti.observable.write

 

We also tried adding all the roles mentioned in the System Admin except for the "admin" role to our App admin role, but it still did not work.

 

Can someone help us determine what could be the reason for this exception and how to resolve it?

Thanks

5 REPLIES 5

From Background script you need to call like as below:

 

var signingAPI = new sn_auth.RequestAuthAPI(httpRequestData, credential);

var output = signingAPI.generateAuth();

 

output should generate signing request.

since RequestAuthAPI look for 2 parameters - httpRequestData and credentials

 

Here endpoint is url for S3 bucket and with action SendMessage and accept message

var endpoint= "https://third-party-endpoint";

var httpRequestData = new sn_auth.HttpRequestData(); httpRequestData.setEndpoint(endpoint); httpRequestData.setService(‘s3’); httpRequestData.setRegion(‘us-east-1’); httpRequestData.setHttpMethod(“PUT”); var content = “Action=SendMessage&MessageBody=This is a test message”; httpRequestData.setContent(content); httpRequestData.addHeader(‘x-amz-acl’ , ‘public-read’ );

 

 

credentials is used which you already configured in your algorithm step, use that records sys_id to for authenticaltion

 

var credential = new sn_cc.StandardCredentialsProvider().getAuthCredentialByID("<sys id for credentials configured>");