bet
bet

Reputation: 1002

Jmeter - passing JSON response array to the next graphql http request

I have 2 graphql http requests as following.

The first http request's response returning json like so:

{"data":{"customers":{"customerIds":["0e1c7b05-79c6-40c6-9144-7230a836fe04", "45677b05-79tt-56c6-9144-7230a836bbbb"]}}}

I then created the json extractor and the beanshell to save the customer ids in the property

enter image description here

enter image description here

The 2nd Http request then using the above customerids property as part of the graphql request body

enter image description here

but I;m getting the 500 InternalServerError due to the quotes in the list customerids below not being escaped. how can i escape them ?

POST data:
{"query":"query getCustomerInfo {\n  getCustomerInfo(customerIds: \"["0e1c7b05-79c6-40c6-9144-7230a836fe04"]\") {\n firstName\n lastName\n school\n }\n}"}

Upvotes: 0

Views: 354

Answers (1)

Dmitri T
Dmitri T

Reputation: 168072

  1. Don't inline JMeter Functions or Variables into your scripts

    When using this feature, ensure your script code does not use JMeter variables directly in script code as caching would only cache first replacement. Instead use script parameters.

  2. Don't use Beanshell, since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting

So replace your Beanshell Assertion with the JSR223 PostProcessor and use the following code:

props.put("customerIds",vars.get("customerIds").replaceAll("\"","\\\\\""));

This way you will get the following customerIds property value:

[\"0e1c7b05-79c6-40c6-9144-7230a836fe04\",\"45677b05-79tt-56c6-9144-7230a836bbbb\"]

Upvotes: 1

Related Questions