Info Message{"error":{"message":"User Not Authenticated","detail":"Required to provide Auth informat

venkata sai alu
Tera Contributor

Hi,

 

I am able to get the access and refresh token for instance-to-instance integration, but I am getting this error: (Info Message

{"error": {"message": "User Not Authenticated", "detail": "Required to provide Auth information"}, "status": "failure"})
Kindly suggest any solution.
13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

@venkata sai alu 

You are saying you are able to get the token but are you getting that error message in subsequent API call?

please share some more details.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar yes,

 

Here I am implementing OAuth 2.0 for instance-to-instance integration (like Instance A and Instance B).

 

if I create one incident in Instance A then same incident should be created in Instance B with this OAuth 2.0 integration, I can be able to generate refresh token and access token but when I create incident in Instance A it is showing the below error. screenshot shared for your reference.

venkatasaialu_0-1737522325341.png

 

@venkata sai alu 

seems you are not sending the token received correctly in the actual API call

Please share your complete script with which you are consuming the token API and the actual API

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar yes,

 

Here I am implementing OAuth 2.0 for instance-to-instance integration (like Instance A and Instance B).

 

if I create one incident in Instance A then same incident should be created in Instance B with this OAuth 2.0 integration, I can be able to generate refresh token and access token but when I create incident in Instance A it is showing the below error. screenshot shared for your reference.

venkatasaialu_0-1737531521696.png

 

Below is the script include code, i will call this script include from scheduled job periodically and i will generate refresh token and i call this script from business rule to generate access token(business rule is triggered when incident is created).

 

var testDemoUtils = Class.create();
testDemoUtils.prototype = {
    initialize: function() {},

    type: 'testDemoUtils',
    generateRefreshToken: function() {
        gs.log('script includes called');
        var oauthcli = new sn_auth.GlideOAuthClient();
        var parameters = {
            grant_type: "password",
            username: "vinoth",
            password: "y?eQKtnA7vmnQ;EWoUM*jTN%-t-=Gy.6d$cY?QYmW_eaW1tyMs&8^R^Pg_xt;y;9TzkIKa43U}c+VN.8CG=,9$F2"
        };
       
        var jsonParams = new JSON();
        var tokenResp = oauthcli.requestToken('instanceToInstance_configuration', jsonParams.encode(parameters));
        var tokens = tokenResp.getToken();
       
        gs.setProperty('instanceToInstanceIng', tokens.getRefreshToken());
        gs.log("Refresh token "+tokens.getRefreshToken());
    },
    getAccessTokens: function(refreshToken) {
        gs.log("Refresh Token in access token si- "+refreshToken);
        //gs.log("getting Access token");
        var cliReq = new sn_auth.GlideOAuthClientRequest();
        cliReq.setGrantType('refresh_token');
        cliReq.setRefreshToken(refreshToken);
        cliReq.setScope(null);
       
        var oauthCli = new sn_auth.GlideOAuthClient();
        var tokResp = oauthCli.requestTokenByRequest('instanceToInstance_configuration', cliReq);
        var tokens = tokResp.getToken();
        return tokens.getAccessToken();
       

    },
    type: 'testDemoUtils'
};

 

Business rule script

 

(function executeRule(current, previous /*null when async*/ ) {

    try {
        var demoAccToken=new testDemoUtils().getAccessTokens(gs.getProperty('instanceToInstanceIng'));
        gs.log(demoAccToken+' access token in BR');
        var r = new sn_ws.RESTMessageV2('instanceToInstance_usecase', 'createIncident');
        r.setStringParameterNoEscape('access_token',demoAccToken);
        var response = r.execute();
        var responseBody = response.getBody();
        var httpStatus = response.getStatusCode();
        gs.addInfoMessage(responseBody);
        } catch (ex) {
        var message = ex.message;
    }

})(current, previous);
 
Rest message snaps
 
venkatasaialu_2-1737531869181.png

 

venkatasaialu_3-1737531929459.png

 

venkatasaialu_4-1737531960833.png