I have the following URL that I would like to test in Postman. However I would like to break down the array for easier testing for example as Form-data (or other). How would I setup this array in Postman?
Full URL
/inventory-results?query={"query":{"model":"xyz","condition":"new","options":{},"arrangeby":"Price","order":"asc","market":"CA","language":"en","super_region":"north america"}}
UPDATE:
How would I build this URL in Swift 5.x using URLComponents?
var urlComponents = URLComponents()
urlComponents.scheme = "https"
urlComponents.host = "www.yoururl.com"
urlComponents.path = "/api/v1/inventory-results"
let query = [
URLQueryItem(name: "TrimCode", value: "$MT314"),
URLQueryItem(name: "model", value: "m3"),
URLQueryItem(name: "condition", value: "new"),
URLQueryItem(name: "arrangeby", value: "Price"),
URLQueryItem(name: "order", value: "asc"),
URLQueryItem(name: "market", value: "CA"),
URLQueryItem(name: "language", value: "en"),
URLQueryItem(name: "super_region", value: "north america"),
]
The above returns the following URL, which is incorrect.
https://www.yoururl.com/api/v1/inventory-results?TrimCode=$MT314&model=m3&condition=new&arrangeby=Price&order=asc&market=CA&language=en&super_region=north%20america
/inventory-results?query={"query":{"model":"xyz","condition":"new","options":{},"arrangeby":"Price","order":"asc","market":"CA","language":"en","super_region":"north america"}}
the URL if its a valid one then it means accepts data as query parameter, you cannot decide to send query parameter as form data or something else. Its the servers decision to implement how the data should be received. So it looks like the server accepts data as query parameter only
what you can do is replace the content with a variable
/inventory-results?query={{data}}
now in pre - request do:
let data = {
"query": {
"model": "xyz",
"condition": "new",
"options": {},
"arrangeby": "Price",
"order": "asc",
"market": "CA",
"language": "en",
"super_region": "north america"
}
}
//make some changes if you want to data and then
pm.variables.set("data", JSON.stringify(data))
Which in swift:
var urlComponents = URLComponents()
urlComponents.scheme = "https"
urlComponents.host = "www.yoururl.com"
urlComponents.path = "/api/v1/inventory-results"
let query = [
URLQueryItem(name: "query", value: "{\"query\":{\"model\":\"xyz\",\"condition\":\"new\",\"options\":{},\"arrangeby\":\"Price\",\"order\":\"asc\",\"market\":\"CA\",\"language\":\"en\",\"super_region\":\"north america\"}}")
]