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/vnd.oracle.adf.resourceitem+json")
val authorization2 = Map("Authorization" -> "Basic REDACTED")
val restFrameworkVersion = Map("REST-Framework-Version" -> "6")
private var token = ""
val auth = exec(getAuthToken())
def getAuthToken() =
exec(
http("POST OAuth Req")
.get("https://epiw.gamma.spectra.us-phoenix-1.ocs.oc-test.com/api/erp/tokenRelay")
.headers(authorization2)
.check(bodyString.saveAs("access"))
.check(status is 200))
.exec{session => { token = session("access").as[String]
session}}
val authorization3 = Map("authorization" -> "Bearer ${access}")
def fetchSetupData () =
exec(
http("Expenses - fetchsetupdata")
.post(url+"/resources/v0/expenses/action/fetchSetupData")
.header("content-type","application/vnd.oracle.adf.action+json")
.headers(authorization3)
.headers(restFrameworkVersion)
.body(ElFileBody("bodies/fetchSetupData.json")).asJson
.check(status.in(200))
)
}