Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Use Bearer token in Credential for REST Integration

Rashi Kulshresh
Giga Contributor

Hi , 

I am doing a REST Integration using flow designer. For Authentication, I am using bearer token, which needs to be send in Authorization header. But Instead of directly putting the token in Authorization header, I want to use Credential Alias. But I am not able to find suitable credential type to put Bearer token. I cant use Oauth type credential as I don't have client Id and Client Secret. I have direct generated token. 

I tried API key credential but in runtime its not picking the Authorization header automatically . And failing with error "Error: U,Detail: Unexpected token: U" . 

 

@Ankur Bawiskar @Chuck Tomasi @Brad Tilton Please help.

 

Thanks.

8 REPLIES 8

You first need to select the Connection Alias in the REST Step (in your Screenshot it's empty). Only then the Credential Variable will become available in the REST Step.

olivierneveu
Tera Contributor

There is another solution

 

like Niklas but I still use the credential alias

you add a get connection info step, the credential is a API KEY type.

 

olivierneveu_0-1676467502039.png

then you use the cred value in the rest step

 

olivierneveu_1-1676467583318.png

 

Ravi Kand
Tera Contributor

 

Hi,

 

POST Method.

While testing through REST Messages, I am getting the below error.

Request not sent to uri= https://xxx-itso-api/api/qs/oa2/v1/ : java.net.UnknownHostException: xxx-itso-api

 

Please help. Thank you.

franciscoco
Giga Contributor

Hi. This is an old post, but after creating a ticket with ServiceNow support for the exact same issue, I was given a secure workaround.

1. Create a system property type password2 to store the bearer token
2. Add a Script Step inside the action that contains the REST step.
Retrieve the token from the system property and expose it as an output with name "password" or "token" like so:

outputs.token = gs.getProperty('x_yourapp.bearer_token') || '';

3. Set up the rest step:
Define Connection inline
Base url + resource path
Configure the Authorization header like so:

Captura de pantalla 2026-03-17 143721.png