0

I am trying to do a rest call to jira and the jql is as below.

jql="Project" = "Test: Dev int: commons & Uig mat"

so when i do the rest call to jira, it is replacing the jql as below:

jql="Project" = "Test: Dev int: commons ',' Uig mat"

so, the & is being replaced with "," which is throwing an error as that project is not available in jira

I tried replacing the "," with &, it is again replacing it with "," while it is run.

import requests

url = "https://jira.com/login/rest/api/2/search"
querystring = {jql='working Project' = 'Test: Dev int: commons & Uig mat'}


headers = {
    'content-type': "application/json",
}

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

I want to pass in exact string to jira to process and do the query

Kumar
  • 67
  • 1
  • 10
  • 1
    As it stands your `querystring` code isn't valid python. If you have double-quotes in your string, consider making your outer set of quotes be single-quotes, so you don't have to escape the double-quotes inside. – Green Cloak Guy Jul 16 '19 at 17:04
  • @GreenCloakGuy -- thanks for the reply, but that code was from postman after processing, so it is changing the actual jira api call to that. but now i directly did a api call, it is still same error. { "errorMessages": [ "Error in the JQL Query: The quoted string 'Test: Dev int: commons ' has not been completed. ], "errors": {} } – Kumar Jul 16 '19 at 17:15
  • 1
    You can't put ampersands and spaces into URLs. Maybe you need to [URI encode](https://stackoverflow.com/questions/46783078/uri-encoding-in-python-requests-package) them? – Boris Verkhovskiy Jul 16 '19 at 17:17
  • Alternatively, have you tried escaping the ampersand with the backslash character? (which may necessitate doing double-backslash to escape the backslash character itself) – Green Cloak Guy Jul 16 '19 at 17:17
  • @GreenCloakGuy - I escaped it using \\ and \ but no luck, throws error. { "errorMessages": [ "Error in the JQL Query: The escape sequence has not been completed. The valid escape sequences are \\', \\\", \\t, \\n, \\r, \\\\, '\\ ' and \\uXXXX.], "errors": {} } – Kumar Jul 19 '19 at 18:45
  • Can you try putting the string in triple quotes and then see if it's working ? Example - """ """ – Gagan Jul 19 '19 at 18:52
  • i just replaced the & with %26 and it worked just fine. – Kumar Jul 19 '19 at 20:36

2 Answers2

1

I just replaced & with %26 and it worked just fine

Kumar
  • 67
  • 1
  • 10
0

Had a problem with Jira Jql query, solved with %26. This is an example :

{
"key": "search?jql= project = \"SS\" AND \"Customer Request Type\" = \"Infinity %26 Website (SS)\" AND \"Infinity Customer ID\" ~ \"417761\""
}
dobrivoje
  • 848
  • 1
  • 9
  • 18