1

I am trying to take follow Postman Get request to Microsoft Graph API and convert it into Karate test

https://graph.microsoft.com/v1.0/users/moo@moo.com/messages?$search="body:'979f13ea-5c87-45e3-98e2-7243d321b238'"

The issue I am having is how to handle the query parameters with the single quote inside the double quotes.

TMac
  • 75
  • 5

1 Answers1

0

Try this:

* url 'https://httpbin.org/anything'
* param $search = `"body:'979f13ea-5c87-45e3-98e2-7243d321b238'"`
* method get

Actual request:

1 > GET https://httpbin.org/anything?%24search=%22body%3A%27979f13ea-5c87-45e3-98e2-7243d321b238%27%22
1 > Host: httpbin.org
1 > Connection: Keep-Alive
1 > User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.5)
1 > Accept-Encoding: gzip,deflate

But, you can see from the server response that the data was encoded correctly:

1 < 200
1 < Date: Mon, 09 Jan 2023 18:52:15 GMT
1 < Content-Type: application/json
1 < Content-Length: 516
1 < Connection: keep-alive
1 < Server: gunicorn/19.9.0
1 < Access-Control-Allow-Origin: *
1 < Access-Control-Allow-Credentials: true
{
  "args": {
    "$search": "\"body:'979f13ea-5c87-45e3-98e2-7243d321b238'\""
  }, 
  "data": "", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept-Encoding": "gzip,deflate", 
    "Host": "httpbin.org", 
    "User-Agent": "Apache-HttpClient/4.5.14 (Java/17.0.5)", 
    "X-Amzn-Trace-Id": "Root=1-63bc625f-36a4b2e92b1976b303454a8a"
  }, 
  "json": null, 
  "method": "GET", 
  "origin": "49.205.149.94", 
  "url": "https://httpbin.org/anything?%24search=\"body%3A'979f13ea-5c87-45e3-98e2-7243d321b238'\""
}

Using back-ticks gives you a nice option to dynamically change data:

* def id = '979f13ea-5c87-45e3-98e2-7243d321b238'
* param $search = `"body:'${id}'"`

Escaping the single-quote would also work:

* param $search = '"body:\'979f13ea-5c87-45e3-98e2-7243d321b238\'"'

Also see: https://stackoverflow.com/a/59977660/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Thank you the back ticks work perfect. I will have to keep httpbin.org in mind to troubleshoot and ask more detailed question. – TMac Jan 09 '23 at 19:38