Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Using the Jira Assets REST API to query for an object that contains a double quote in one of its att

Andrew November 21, 2023

I'm trying to use the Jira Assets REST API to query for an object that contains a double quote in one of it's attributes and I'm not able to structure the query successfully. If I try escaping the double quote with a backslash, the query is accepted but it doesn't return the object e.g. ("%22" is an encoded double quote and "%5C" is an encoded backslash):

This query fails with a syntax error:
https://<jira-server>/rest/assets/1.0/aql/objects?qlQuery=objectSchema=%22Schema%22%20AND%20objectTypeId=1234%20AND%20%22Attribute%22=%22Value%20with%20a%22%22

And this query doesn't return the object:
https://<jira-server>/rest/assets/1.0/aql/objects?qlQuery=objectSchema=%22Schema%22%20AND%20objectTypeId=1234%20AND%20%22Attribute%22=%22Value%20with%20a%5C%22%22

I've read it might be possible to change the enclosing double quotes to another character e.g. a single quote or a backtick but when doing so I get other syntax errors and if the attribute contained one of these characters I'd wind up in the same situation and need to escape that character instead.

1 answer

0 votes
Peter_DevSamurai
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
November 21, 2023

Dealing with special characters like double quotes in API queries, particularly in a Jira Assets REST API context, can be tricky. The issue you're encountering is common when dealing with encoded query strings. Here are a few strategies you can try:

1. URL Encoding the Entire Query: Instead of encoding just the double quotes and backslashes, try URL encoding the entire query string. This can sometimes resolve issues where certain characters are interpreted incorrectly.

2. Using Single Quotes for Encapsulation: If Jira's AQL (Asset Query Language) allows, try using single quotes to encapsulate the attribute values instead of double quotes. This could look something like attribute='Value with a "quote"'. This approach might vary depending on how Jira AQL interprets single quotes.

3. Nested Escaping: Sometimes, double escaping is necessary, especially in contexts where the query is parsed multiple times. This would mean using a backslash to escape another backslash that is escaping the quote. For example, in your query, %5C%5C%22 might be used to represent an escaped double quote.

4. Using Different Attribute Identifiers: If the AQL supports it, try using different identifiers for the attributes. Instead of using double quotes around the attribute name, see if it's possible to use no quotes or brackets.

5. Checking for Additional Encoding Requirements: Ensure that other parts of your query are correctly encoded too. Sometimes, the problem might not lie with the double quotes but with other parts of the query string.

6. Consulting Jira Documentation or Support: Review the Jira Assets REST API documentation for specific guidelines on handling special characters in AQL queries. If the documentation isn’t helpful, consider reaching out to Atlassian support or community forums for more targeted assistance.

7. Testing with a REST Client: Use a REST client tool like Postman to test your queries. These tools often handle encoding more gracefully and can help you identify where the issue might be occurring.

If you've tried these methods and are still facing issues, it would be helpful to have more specific details about the error messages you're receiving. This can provide clues about what the API is expecting or where the query is failing.

Andrew November 21, 2023

Hi @Peter_DevSamurai thanks for your response. I tried almost all your suggestions before posting my question. Interestingly, I've just discovered that if I simply change the "=" to a " LIKE ", the object is returned by the query, which seems to suggest my encoding is ok and maybe there is a bug in how the equals operator interprets the input.

As for more details about the errors, when using my first example, it produces a syntax error indicating the position of the syntax error is where the double quote in the attribute value is. The second example doesn't produce an error but simply fails to return the object with the value of the attribute.

Andrew November 21, 2023

The other potentially relevant detail is that the Type Value of the Attribute is Textarea.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events