1

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
Paul S.
  • 1,342
  • 4
  • 22
  • 43

2 Answers2

2
/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\"}}")
         ]
PDHide
  • 18,113
  • 2
  • 31
  • 46
0

I think you have the right idea but you want to maintain the object notation style, you would want to URLencode this location string as some of these characters will be changed through browser behavior. Below is an example:

/inventory-results?model=xyz&condition=new&arrangeby=Price&eorder=asc&market=CA&language=en&super_region=north america

I also think in this case, you would be better off to code all of these as GET variables rather than trying to make the call though one giant object. Not sure what language you are using but most of them will complete this request and formulate the call appropriately for you if handled properly.

Since you are not passing any keys or private data, keeping it in an object notation will work against you in the end

  • I scraped the URL and results presented from Charles to see what was behind a website query. I want to strip it out and play further with Postman, thus the reason the query looks like it does. I can't really change it as recommended. – Paul S. Jun 09 '21 at 15:23