Cannot figure out what is wrong with my code

I’m trying to build a login scenario; it posts a json to the auth service to get a jwt_token

package perfpoc

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import scala.concurrent.duration._
import scala.util.Random

class POC1 extends Simulation {

val sessionHeaders = Map(“Authorization” → “Bearer ${authToken}”,
“Content-Type” → “application/json”)

val baseUrl = “https:///auth/auth/token”
val httpProtocol = http
.baseUrl(baseUrl)
.acceptHeader(“text/html,application/xhtml+xml,application/json,application/xml;q=0.9,/;q=0.8”) // Here are the common headers
.acceptEncodingHeader(“gzip, deflate”)
.acceptLanguageHeader(“en-US,en;q=0.5”)
.userAgentHeader(“Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0”)

val headers_10 = Map(“Content-Type” → “application/json”)
val ScheduleRefs = Iterator.continually(Map(“ScheduleRefs” → Random.alphanumeric.take(20).mkString))

val scn = scenario(“Login Test”)
.exec(http(“login”)
.post("/auth/token")
.headers(sessionHeaders)
.body(StringBody("""{
“grant_type”:"",
“email”:"",
“password”:""
}
“”")).asJson
.check(jsonPath(“access_token”).exists.saveAs(“authToken”)))

my scenario returns login: failed to build request: No attribute named ‘authToken’ is defined. It seems simple and I pulled this structure from sample code.

Any help would be greatly appreciated.

failed to build request: No attribute named ‘authToken’ is defined is most likely not your first failure.

The previous request definitively fails because “access_token” is not a valid JsonPath expression.

Please read the kind-of spec to learn the syntax: https://goessner.net/articles/JsonPath/

i’ve changed the jsonPath to ("$.access_token") but i’m still getting the ‘authToken’ error. This is what the api spits out when authenticated

`

{
“access_token”: “eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJlZWU5ZTlmNC01MDIyLTRkMmYtODM3YS0wNzU1ODFhNWFhNjAiLCJpYXQiOjE1NTQ0MDE4OTUsImlzcyI6Imh0dHBzOi8vZGV2ZWxvcG1lbnQudm9sYW50ZWNsb3VkLmNvbS9hdXRoLyIsImV4cCI6MTU1NDQzNzg5NSwibmFtZSI6InRlc3QiLCJjdXJyZW50X3RlbmFudCI6IjYxMThhYzlmLTZiNWQtNDdjZi04OTM3LTJmYjA3NWJjZDU1ZiIsImVtYWlsIjoidmV0ZXN0QHZvbGFudGVzeXN0ZW1zLmNvbSIsImltZyI6Imh0dHBzOi8vd3d3LmRyb3Bib3guY29tL3Mvb3Q1cHZ4b3g1ZTR2bWVuL1ZPTEFOVEUtaWNvbi0tLWNvbG91ci5wbmciLCJqdGkiOiJlZjJlNTdhOS1lYzM1LTRjMDMtODE4My02MWQ5NmI3N2YwNmUifQ.VVaNqr0AB5wgTFI4TnucTm6HjbhvwY14pC2DHnRKAhds1DUdMA558OCFmIgxU5bNBK30TWpVHAQ-00vgld9bmA”,
“refresh_token”: “eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJlZWU5ZTlmNC01MDIyLTRkMmYtODM3YS0wNzU1ODFhNWFhNjAiLCJpYXQiOjE1NTQ0MDE4OTUsImlzcyI6Imh0dHBzOi8vZGV2ZWxvcG1lbnQudm9sYW50ZWNsb3VkLmNvbS9hdXRoLyIsImp0aSI6ImVmMmU1N2E5LWVjMzUtNGMwMy04MTgzLTYxZDk2Yjc3ZjA2ZSIsImV4cCI6MTU1NTYxMTQ5NX0.cL10eNFs3ioHGpUEHU1RziC6ApgsTYyeJXZ4Cq7Y8TQXTHE8-JJPBi_aEjCPD_qs_ANXxsh20EhNiEtyrLs4Ug”
}

`

Should work.
Lower logging level in logback.xml to debug payloads.

Thanks!, I think I figured out what happened. Now I have saved the woken but it’s not passing on the next call

val sentHeaders = Map(“Content-Type” → “application/json”, “Authorization Bearer” → “authToken”, “Accept” → “application/json”)

.exec(http(“Get All Sites”)
.get("/api/store/v1/sites")
.headers(sentHeaders)
.check(status.is(200))
)

as you can see headers is empty so i’m fed 403

I figured out what was wrong; thanks!