Hello, I am looking to extract the "g" value and t...
# help
d
Hello, I am looking to extract the "g" value and the "s" value from this endpoint and include it in the repsonse...the problem is the order of this values in the list change...can I directly pull out the key value pairs for "g" and "s"?
"/apq/getStoreItem/storeExecutionItemInfoV3?q=[{"c":"US","g":"806594766724","t":"GTIN14","s":"2473"}]"
I always want to return 806594766724 and 2473 even if the order of these values changes...
l
Hi, I think you can make use of the fact that the
q
parameter is valid json. You could parse the
q
parameter value and reference the
g
and
s
values directly so it won’t matter what order they are in.
With this mapping:
Copy code
{
  "name": "query-parameter-parsing",
  "priority": 1,
  "request": {
    "urlPattern": "/apq/getStoreItem/storeExecutionItemInfoV3\\?q=(.*)",
    "method": "GET"
  },
  "response": {
    "status": 200,
    "bodyFileName": "query-parameter-parsing.json",
    "headers": {
      "Content-Type": "application/json"
    },
    "transformers": [
      "response-template"
    ]
  }
}
And this body file:
Copy code
{{#parseJson 'parsedObj'}} {{request.query.q}} {{/parseJson}}
{
  "g": "{{parsedObj.[0].g}}"
  "s": "{{parsedObj.[0].s}}"
}
And a get request like this -
<http://localhost:8080/apq/getStoreItem/storeExecutionItemInfoV3?q=[{>"c":"US","g":"806594766724","t":"GTIN14","s":"2473"}]
Should give you this result:
Copy code
{
  "g": "806594766724"
  "s": "2473"
}