Azure Load Testing Series - Accessing bearer token in Jmeter using JSON extractor

About this blog

Hey folks!, In this blog we will see how to pass bearer token dynamically while running the test plans.

Mock API

In order to cover the scenarios, I have used a mock API that exposes token endpoint and a dummy GET endpoint.

Extract token within a thread group using JSON Extractor

Configuring GET endpoint with HTTP Header manager

  • Create ThreadGroup and Add HTTP request , ThreadGroups->Add->Sampler->HTTP Request

  • Above GET endpoint requires an bearer token to authorize the call.

  • We can add the headers by adding config element under the HTTP Request option menu

  • In the HTTP header manager add authorization key value as below
Authorization : Bearer ${auth_token}

  • ${auth_token} - We need to somehow get this bearer token dynamically to make sure we send the valid authorization header along with the GET endpoint

Configuring Token endpoint

  • Add below key vaule in the Headers manager

  • Request body we will send along with the POST call are
    • grant_type : password
    • username : Steve Smith
    • password : p$ssw0rd
    • client_id : test
    • client_secret : 99ae8af9-cf8a-4cb3-89b2-9a42b97762b2

  • Add listener view result from HTTP request -> Add -> Listener -> View result tree

  • Now click on Run for the Get access token endpoint and you can see the bearer token generated in the Response body

Create JSON extractor

  • In order to make use of this token generated in other HTTP requests create a JSON extractor from HTTP Request->Add->Post Processors->JSON Extractor

  • Provide “Names of created variables” and JSON Path expression as below
Names of create variables : auth_token
JSON Path expressions: $.access_token

  • Now we can pass on “auth_token” variable in another HTTP request within the same Thread Group

Request Headers

  • Now we can see that the bearer token in the request headers

Next steps

In our next blog we will see how to pass access token dynamically between different thread groups

Join us

Please go ahead and join our discord channel ( to give some valuable feedbacks