Hi,
I am trying to inject date variable to my json request body but getting this error:
body:
[{"errors":[{"message":"Variable $limitingPeriodEnd of type ISO8601DateTime was provided invalid value","locations":[{"line":1,"column":203}],"extensions":{"value":"#{endOfWeekDate}","problems":[{"path":[],"explanation":"Could not coerce value \"#{endOfWeekDate}\" to ISO8601DateTime"}]}},{"message":"Variable $limitingPeriodStart of type ISO8601DateTime was provided invalid value","locations":[{"line":1,"column":240}],"extensions":{"value":"#{todaysDate}","problems":[{"path":[],"explanation":"Could not coerce value \"#{todaysDate}\" to ISO8601DateTime"}]}},{"message":"Variable $now of type ISO8601DateTime was provided invalid value","locations"
Here is the session information with the generated date values:
Session:
Session(Booking manager Navigation Booked,2,HashMap(gatling.http.cache.wsBaseUrl -> ... gatling.http.cache.baseUrl -> ., todaysDate -> 2022-11..-02T14:04:42.607Z, endOfWeekDate -> 2022-11-08T15:04:42.607Z
Here how I inject them:
val dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"))
val timeNow = (Calendar.getInstance())
val scnBookingManagerBooked = scenario("Booking manager Navigation Booked")
.exec(session => {
session.set(
"todaysDate",
dateFormat.format(timeNow.getTime())
)
})
.exec(session => {
timeNow.add(Calendar.DAY_OF_WEEK, +6)
session.set(
"endOfWeekDate",
dateFormat.format(timeNow.getTime())
)
})
Finally here is the .json file I use as the request body for the graphql call:
{
"operationName": "Bookings",
"variables": {
"bookingType": null,
"first": 15,
"limitBookings": true,
"limitingPeriodEnd": "#{endOfWeekDate}",
"limitingPeriodStart": "#{todaysDate}",
"now": "#{todaysDate}",
"safeguardCheck": null,
.....
I appreciate if you can help me figure out why I am getting the error even the format is correct.
I tried changing the data.format to String but that didn’t work.
One last thing. I don’t get an error when I copy and paste the date format from the session (logs of previously ran test), into the json file manually and run the test. So the format is the correct format.
Thanks,