Life as a developer

Calling an API with Bearer token using Postman

The Chrome extension Postman is a great tool for testing APIs. It is simple to use and have several useful features such as collections for easy retrieval of requests. If you need to test authentication or want to make requests where a Bearer token is required, you need to add a token to the header.

One way to do this is to use Authentication Helpers. They can help you if you use Basic Auth or OAuth. But if you just need to pass a Bearer token, it is just as easy to set it up yourself.

First you need to get a hold of a valid token. Your API should have a Login endpoint that you can call to retrieve the token.
Postman request
If you have made a successful Post request, you should get a response containing a Bearer token. Copy it and add it to your header.

key= "Authorization", value = "Bearer [your token]"

. You can leave Type under Authorization to “No auth”.
Postman response

Add that header to all request that require authentication and that is it.

goldnarms

Arnstein Johansen is a .NET Developer with a speciality in web development, but he also dabbles in mobile development and everything new and exciting. Arnstein works for Itema AS, a mid-size consultant agency in Trondheim. Itema has 25 consultants and recently won the prize for Norway's best workplace. He likes to share his knowledge by holding talks for others, either it is clients, colleagues or likeminded developers in user groups. He has hands-on experience from large projects, the latest from Urørt where he leads a team of developers creating a music service used by around 100000 users.

No Comments

Leave a reply