7th Circle of Hell : Figuring out how to CQL Search via a Jira Automation Web Request

Evan Nixon July 3, 2022

Hello All, Everyone, and/or etc,


I am once again up to my neck in it ("it" being integration hell) and managing to squash all bugs in sight.....except for what I thought should be the easiest part. Pure unadulterated hubris, I know. 

This is among the very last steps of an automation I've been struggling to get perfected for weeks, so any help on crossing this last hurdle would be hugely appreciated. 



 

The Goal :

Complete a CQL Search using Jira Automation's "Send Web Request" action. 

Where I'm stuck : 

I've managed to somehow get the authentication working (no thanks to documentation that says 5 different things about how to pass basic authentication to Confleunce, none of which actually work the same way via the webhook), but now I just cannot get the payload correct. 

All I need is {{customfield.value}} to get passed on to the end of the request's URL. 

Screenshot 2022-07-04 053349.png

 

No amount of begging/pleading/{{.urlEncode}}-ing has gotten me anywhere. 

Does anyone have any hints on how I can just get this friggin CQL search done?

 

Thank you!

2 answers

0 votes
Agraj Mangal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 4, 2022

Hey @Evan Nixon 

What error/exception are you getting when doing the CQL search?

Using the Log Action You can try logging the result of `.urlEncode` if you are not sure what value it is encoding to   https://support.atlassian.com/cloud-automation/docs/debug-an-automation-rule/#2.-Debugging-smart-values 

Cheers,

Agraj

0 votes
Dam
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 3, 2022

Hi @Evan Nixon 

To search in title only you should use:

BASE_URL/wiki/rest/api/search?cql=(type=page%20AND%20title~test)

This request will search for pages only, with a title like "test". If you want to search for the exact page title use "=", if you want to search for a page containing a word use "~". 

 

The API doc is here: 
https://developer.atlassian.com/cloud/confluence/rest/api-group-search/

The doc about advanced searching using CQP with the API is here: 
https://developer.atlassian.com/cloud/confluence/advanced-searching-using-cql/

I hope this helps.

Cheers,
Dam. 

Evan Nixon July 4, 2022

Hi @Dam, thanks very much for getting back to me on this!

While that is a really good tip on how to make my query more specific (that I am going to use) I think I may not have been clear enough on exactly what I need help with on this. 

So, to be more explicit on my problem : 

Screenshot 2022-07-04 203443.png

 

The problem is that I cannot get a smart value to pass in to the query, no matter how many times I try, how nicely I beg, or how loudly I scream at/near/adjacent to the sky.

 

Here is the smart value I'm trying to use : 

{{customfield_10675.leafValue}}

 

And here is a computer once again leaving a hot steaming pile on my chest because it's jealous of my meat prison : 

Screenshot 2022-07-04 203848.png

405 : Both the number of times I've hated this and the relevant error code. Neat!

 


 

@Agraj Mangal thank your as well for your reply! I generally find the "Validate Your Web Request Configuration" option easier / better / big gooder-er in these circumstances just by virtue of : 

A) Less click more do.
B) It parses smart values, and provides a full read-out of the Request/Response Headers and Payloads (which makes the Audit Log super jealous).

 

Here is an example which illustrates my objectively true and based point : 

Screenshot 2022-07-04 210509.png

 

The point that I find raises my blood pressure more than a deep fried double down ice cream sandwich the most interesting is the "expecting a value for operator '=' after field 'title'". This tells me two things : 

  1. That the (smrt) value is not being passed along whatsoever. 
  2. My life was not supposed to go like this.

 

I have tested this with other Smart Values and get pretty much the same result constantly, which is frustrating. But even more frustrating will be when someone replies to this thread with the correct answer and it's both incredibly obvious and has been right infront of my big ol' smell horn this whole time. 

Agraj Mangal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 4, 2022

Ok couple of things 

  1. 405 typically means you are not using the right HTTP method to query - I can see in the above screenshot you are using GET but can you please double check in the actual configured rule - also you may not be able to use a Custom Body with GET if the CQL endpoint does not support that. 
  2. Can you try with some other smart value if that is also not being able to resolve or is it just custom fields that are causing an issue ?

I was able to use the following successfully to call the CQL endpoint 

Automation_-_Jira.png

Edit 1 -- Just tested it works for Custom Fields also. The catch is you would need to enclose the smart values in single quotes in your CQL query if the smart value is resolving to multiple words. An an example try using 

https://****.atlassian.net/wiki/rest/api/content/search?cql=title='{{issue.customfield_10020.name.urlEncode}}'
Like Dam likes this
Evan Nixon July 11, 2022

Alright - I've managed to get it to work.

I'll save the super-long explanation, but the behaviour I was running in to was because many page titles contained dashes "-", which wasn't being handled by the ".urlencode" tag. The only way around this was  and required a workaround by wrapping double quotes around the smart value, but pre URL encoded as in "%22".

This is what the final query looks like using the ".leafValue" of a cascading select list from a custom field (via Prime Custom Fields).

Screenshot 2022-07-11 112611.png

 

This allows me to extract the URL from the response and place a Smart-Embed of the relevant confluence page into a custom field using this string :

[https://*****.atlassian.net/wiki{{webResponse.body.results._links.webui}}|https://*****.atlassian.net/wiki{{webResponse.body.results._links.webui}}|smart-embed]

 

 Like this : 

Screenshot 2022-07-11 112912.png

 

 

Thanks very much for your help!

Like Dam likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events