Issue in receiving OAuth token from Zendesk getting 401 error.

AkashYen007
Tera Guru

Hi Team,

 

I'm new to OAuth 2.0. I'm currently working on configuring OAuth token with our external vendor who uses Zendesk tool and is provider for OAuth token. The did setup and using the provided client-id and client secrate and other details we did setup at our end also with the provided details in Application regiestroy and created one custom script based on OAuthUtil. Tried getting token it's reching the zendesk side but receiving HTTP error 401 - unauthorized error. Tried finding what is the issue here but not able to find it. Any help appriciated. 

Custom Util Script

//* Dont edit this script include. Best practise: Extend this script include and override the functions.
var OAuthCustomHandler = Class.create();
OAuthCustomHandler.prototype = {
    initialize: function(oauthContext) {
        this.oauthContext = oauthContext;
    },

    interceptRequestParameters: function(requestParamMap) {
        // Add/Modify request parameters if needed
        this.preprocessAccessToken(requestParamMap);
    },

    parseTokenResponse: function(accessTokenResponse) {
        this.postprocessAccessToken(accessTokenResponse);
    },

    preprocessAuthCode: function(requestParamMap) {},

    preprocessAccessToken: function(requestParamMap) {
        this.oauthContext.addHeader("Content-Type", "application/json");
        this.oauthContext.addHeader("Accept", "application/json");
    },

    postprocessAccessToken: function(accessTokenResponse) {
        var contentType = accessTokenResponse.getContentType();
        var contentBody = accessTokenResponse.getBody();
        gs.info("Content Type: " + contentType);
        gs.info("Content Body: " + contentBody);
        // if (contentType && contentType.indexOf('application/json') != -1) {
        var tokenResponse = (new global.JSON()).decode(accessTokenResponse.getBody());
        var paramMap = accessTokenResponse.getparameters();
        for (param in tokenResponse)
            paramMap.put(param, tokenResponse[param].toString());
        // }
    },

    type: 'OAuthCustomHandler'
};
 
Application registory setup:
AkashYen007_1-1715930313418.png

 

 
When tried get token:
AkashYen007_0-1715930000784.png
 
In the logs I'm getting this error.
AkashYen007_2-1715930363468.png

 

Let me know if you require any more details.

 

Thanks in advance.

2 ACCEPTED SOLUTIONS

@AkashYen007  401 indicates its authorization error.  

SujathaVM_0-1715950200775.png

 

Non-admins will not be able to retrieve the details: 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783632

 

Create a Zendesk OAuth client : 

https://docs.servicenow.com/bundle/washingtondc-it-asset-management/page/product/software-asset-mana...

 

Also did you try to change the Send credentials as "In Request Body" and test it. If so what was the result?

 

I have come cross the same issue and I had to re-enter the client secret and it worked. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

View solution in original post

12 REPLIES 12

@AkashYen007  401 indicates its authorization error.  

SujathaVM_0-1715950200775.png

 

Non-admins will not be able to retrieve the details: 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783632

 

Create a Zendesk OAuth client : 

https://docs.servicenow.com/bundle/washingtondc-it-asset-management/page/product/software-asset-mana...

 

Also did you try to change the Send credentials as "In Request Body" and test it. If so what was the result?

 

I have come cross the same issue and I had to re-enter the client secret and it worked. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Hi @Sujatha V M,

 

Tried this way also but same error I'm getting.

 

AkashYen007_0-1716185140294.png

Thanks

Thanks a lot for the help on this it helped to get token in our side

Tabassum22
Tera Guru

Hi @AkashYen007,

 

The things which help in troubleshoot are

1. You can use Postman application to check the client ID and secret key is able to hit the Zendesk tool. 

2. Also can use the "Generate Token" which gives you the token and check whether the bearer token is working by using it in postman under authorization select bearer token.

 

By the above you'll get to know the connection is working or not.

 

Please mark it helpful and try to give it a thumbs up if the above helps. Please accept the solution.

 

Thanks & Regards

Tabassum Sultana

Hi @Tabassum22 ,

 

Yes I have verified by going through postman and it is getting access_token there without any issue.

 

Thanks.