, but actually found 401

Hi Team,
Can anyone tell me what is wrong in my code. When I pass the hardcoded bearer token (JWT) directly in fetchSetupData() API everything works fine but when I am trying to generate bearer token dynamically I am getting error 401

object expensesChain {
  val url = s"$baseUrl"+"/api/erp/expenses"
  val jsonHeader = Map("Content-Type" -> "application/")
  val authorization2 = Map("Authorization" -> "Basic REDACTED")
  val restFrameworkVersion =  Map("REST-Framework-Version" -> "6")

  private var token  = ""
  val auth = exec(getAuthToken())

  def getAuthToken() =
      http("POST OAuth Req")
        .check(status is 200))
      .exec{session => { token = session("access").as[String]

  val authorization3 = Map("authorization" -> "Bearer ${access}")

  def fetchSetupData () =
      http("Expenses - fetchsetupdata")

Hi @harshit,

I don’t see any hardcoded bearer token. Only a hardcoded basic auth: “`Redacted” (base64 is not encryption, if this are real credentials, please change).

401 Unauthorized means that the client doesn’t provide credentials and server ask to retry (browser usually open a modal for basic auth)

In your case, you added a map of headers. Please note that you have a Map[String, String] not a Map[String, Expression[String]].
The value won’t be interpreted by Gatling engine to replace the access

You should use the singular header method that accept an Expression[String]

  .header(HttpHeaderNames.Authorization, "Bearer #{access}")

Does that help?
If not, please provide whole (but smallest) simulation.