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.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andrew,
I am running into this issue as well. Did you figure out a solution? I've posted my question here: https://community.atlassian.com/t5/Jira-Service-Management/Calling-Object-AQL-API-fails-when-value-being-filtered-on/qaq-p/2889288#M189210
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Girish Reddy , I think I ended up doing something like this in Python:
aql = ' AND '.join([f'{attribute} {"=" if not chr(10) in value and not chr(34) in value else "LIKE"} "{value}"' if value is not None else f'{value} IS EMPTY' for (attribute,value) in attributes.items()])
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Andrew. I was using the "Post" version of the AQL API and escaping the slash and quote worked. E.g. if my AQL contains the string '9" Laptop', then I encode it as '9\\\" Laptop' in the body of the HTTP Post.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.