Skip to page contentSkip to chat
ServiceNow support
    • Community
      Ask questions, give advice, and connect with fellow ServiceNow professionals.
      Developer
      Build, test, and deploy applications
      Documentation
      Find detailed information about ServiceNow products, apps, features, and releases.
      Impact
      Accelerate ROI and amplify your expertise.
      Learning
      Build skills with instructor-led and online training.
      Partner
      Grow your business with promotions, news, and marketing tools
      ServiceNow
      Learn about ServiceNow products & solutions.
      Store
      Download certified apps and integrations that complement ServiceNow.
      Support
      Manage your instances, access self-help, and get technical support.
Code to access REST end point with JWT Bearer grant type Authorization - Support and Troubleshooting
  • >
  • Knowledge Base
  • >
  • Support and Troubleshooting (Knowledge Base)
  • >
  • Code to access REST end point with JWT Bearer grant type Authorization
KB0822678

Code to access REST end point with JWT Bearer grant type Authorization


1493 Views Last updated : Jan 3, 2025 public Copy Permalink
KB Summary by Now Assist

Summary

Below is a sample code to access REST end point with JWT Bearer grant type Authorization

Instructions

Set up jwt_provider record . After configuration is successful , below code can be executed to access REST end point with JWT Bearer grant type Authorization

var tokenRequest = new sn_auth.GlideOAuthClientRequest();
tokenRequest.setGrantType("urn:ietf:params:oauth:grant-type:jwt-bearer");
tokenRequest.setRequestor("someone@someemail.com");

var oAuthClient = new sn_auth.GlideOAuthClient();
// box_demo is the name of jwt_provider
var tokenResponse = oAuthClient.requestTokenByRequest("box_demo", tokenRequest);
gs.info("Error:" + tokenResponse.getErrorMessage());
var token = tokenResponse.getToken();



if(token) {
gs.info("AccessToken:" + token.getAccessToken());
gs.info("AccessTokenExpiresIn:" + token.getExpiresIn());
// Making a REST call
var restMessage = new sn_ws.RESTMessageV2();
//set the token obtained from above
restMessage.setRequestHeader('Authorization', 'Bearer ' + token.getAccessToken());
restMessage.setHttpMethod("get");
// set end point
restMessage.setEndpoint("https://api.box.com/2.0/folders/109476179807");

var response = restMessage.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log(responseBody);
}





The world works with ServiceNow.

Sign in for more! There's more content available only to authenticated users Sign in for more!
Did this KB article help you?
Did this KB article help you?

How would you rate your Now Support digital experience?

*

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

What can we improve? Please select all that apply.

What are we doing well? Please select all that apply.

Tell us more

*

Do you expect a response from this feedback?

  • Terms and conditions
  • Privacy statement
  • GDPR
  • Cookie policy
  • © 2025 ServiceNow. All rights reserved.