Question

Call web api with bearer token authentication

  • 9 January 2023
  • 3 replies
  • 267 views

Badge +1

Hello everyone,

I need to call a REST API with a Bearer token passed in header of the request (Authorization header). 
How can I configure my rest service isntance to have the bearer parameter filled by K2 ?

 

Thanks for the help,

Regards,

Pierre 


3 replies

Badge +1

Hi Pierre

I got it working this way.

The service instance property should be as this.
In the Default HTTP Header prop, look for the “INSERT TOKEN HERE!” text. You should replace that, with your bearer token.

I hope this will help you :)

Authorization Header Format: Bearer {0}
Default HTTP Request Headers

{"$type":"SourceCode.SmartObjects.Services.Endpoints.Common.HttpHeader[], SourceCode.SmartObjects.Services.Endpoints.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","$values":[{"$type":"SourceCode.SmartObjects.Services.Endpoints.Common.HttpHeader, SourceCode.SmartObjects.Services.Endpoints.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","Name":"Authorization","Value":"INSERT TOKEN HERE!"},{"$type":"SourceCode.SmartObjects.Services.Endpoints.Common.HttpHeader, SourceCode.SmartObjects.Services.Endpoints.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","Name":"accept","Value":"application/json"},{"$type":"SourceCode.SmartObjects.Services.Endpoints.Common.HttpHeader, SourceCode.SmartObjects.Services.Endpoints.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","Name":"Content-Type","Value":"application/json"}]}

Badge +1

Hi Bjarke,

Thanks for your help, I tested it like that and it works. 

Now I’m trying to send the token of my connected user, because third party tool check the expiration date of the token, so I need to get a fresh token to communicate with my web service.
Did you found any solution on your side ?

 

Thanks !

Badge +1

Hi Pierre

Sorry, i cant help you with that part.

Reply