Get SPECIFIC Assets via REST API - Does exists a way to query them? - Python3

Ian Carlos
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 20, 2023

Hi everyone, hope you're all fine

 

I'm trying to get assets based on their names, customfield values, etc., but I can perform a correct filter, I receive all the assets or none...

 

I have used the AQL Api

 

I'm trying to perform an API call with Python 3 to this URL:

url = "https://api.atlassian.com/jsm/assets/workspace/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/v1/aql/objects?qlQuery= objectTypeId = XX AND Status = 'OPERATIVE'"

But is not working, not asset is retrieved...

 

Could you give me a hand with this? Please

 

It would be great if you can write down an URL example with a field and a customfield (so I could see how to approach), please

 

I have no found useful example in the documentation...

 

Thank you so much for your time!

3 answers

1 accepted

0 votes
Answer accepted
Ian Carlos
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 23, 2023

For anyone wondering what is the problem.

 

The AQL API uses qlQuery

The problem was... that I was doing:

"....qlQuery=objectTypeId = XX AND Status = 'OPERATIVE'"

And it has to be:

'...qlQuery=objectTypeId = XX AND Status = "OPERATIVE"' 

So... the texts have to use "" and not ''

 

And that's it ;) 

David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 23, 2023

Ahh, I hadn't noticed that.

PS. In all of Atlassian's query languages, you only need double inverted commas around the field object if it has spaces in its name. This works just as well:

'...qlQuery=objectTypeId = XX AND Status = OPERATIVE'

 

Like Ian Carlos likes this
Ian Carlos
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 24, 2023

Thanks! I always double quote them because I make the API calls from an API and the values passed could be one or two words, so, just in case

But is good to know for the harcoded or fixed parts, thanks!

0 votes
David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 20, 2023

In addition to what @Hana Kučerová  said, try without the space after the qlQuery= or aqlQuery= parameter:

url = "https://api.atlassian.com/jsm/assets/workspace/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/v1/aql/objects?qlQuery=objectTypeId = XX AND Status = 'OPERATIVE'"

as it might be interpreted as an empty query and the endpoint is then just ignoring everything thereafter

Ian Carlos
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 23, 2023

Hi David! Thank you for your fast reply

 

I have tested various things, and finally found how to make it work, I'll explain:

 

Yes, the AQL API uses qlQuery

Space or not space after the qlQuery parameter doesn't matter

 

The problem was... that I was doing:

"....qlQuery=objectTypeId = XX AND Status = 'OPERATIVE'"

And it has to be:

'...qlQuery=objectTypeId = XX AND Status = "OPERATIVE"'

 

So... the texts have to use "" and not ''

 

Thank you so much for your help!

0 votes
Hana Kučerová
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 20, 2023

Hi @Ian Carlos ,

it seems to me strange, that the parameter would be called qlQuery instead of aqlQuery.

Maybe it is nonsense, but would please try it with aqlQuery?

Thank you.

Ian Carlos
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 23, 2023

Hi Hana! Thank you for your fast reply

 

I have tested various things, and finally found how to make it work, I'll explain:

 

Yes, the AQL API uses qlQuery

The problem was... that I was doing:

"....qlQuery=objectTypeId = XX AND Status = 'OPERATIVE'"

And it has to be:

'...qlQuery=objectTypeId = XX AND Status = "OPERATIVE"'

 

So... the texts have to use "" and not ''

 

Thank you so much for your help!

Like Hana Kučerová likes this
Hana Kučerová
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 23, 2023

Thank you for letting us know!

Like Ian Carlos likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events