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

Sujatha V M
Kilo Patron
Kilo Patron

@AkashYen007 Please the refer the article posted below for the OAuth configurations for the 401 error which might be helpful,

 

https://www.servicenow.com/community/architect-forum/google-calendar-integration-with-servicenow/m-p...

 

SujathaVM_0-1715937548764.png

 

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 ,

 

Thanks for the article but the detailed error I'm getting when saw logs in 

"Content Body: {"message":"Server could not parse JSON","error":"Unprocessable Entity"}".

any help for this issue?

 

Thanks

@AkashYen007  Could you please reconfirm this send credentials as it shows basic authorization header?

 

Can you change it to "In Request Body" and try it?

 

 

SujathaVM_0-1715941221255.png

 

Also see this reference link : https://www.servicenow.com/community/developer-forum/help-with-json-problem/m-p/1986812

 

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.

Yes it's set As Basic Authorization Header

AkashYen007_0-1715942200189.png