Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with API trying to build an aql statement

Ste404
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.
August 2, 2023

Hi there,

I am trying to build a little powershell script just to pull out some information from Assets.

Below is part of the code I am using to try and build out the GET but I keep getting an error that is show below.  If I remove the $encodedQuery after the qlQuery= the whole thing works fine but I get EVERYTHING.

$objectSchema = "IT Assets"
$objectType = "IT Hardware"

# Remove the space before URL-encoding the query string
$encodedQuery = [System.Web.HttpUtility]::UrlEncode("objectSchema='$objectSchema' AND objectType='$objectType'")

$assetUrl = "https://api.atlassian.com/jsm/assets/workspace/$jira_workspace_id/v1/aql/objects?qlQuery=($encodedQuery)"
$response = Invoke-RestMethod -Uri $assetUrl -Headers $JiraHeaders -Method GET

 

Invoke-RestMethod : {"errorMessages":["AQL \"(objectSchema='IT Assets')\" has invalid syntax at position 18 with error message \"no viable alternative at input '(objectSchema='IT A'\""],"errors":{}}
At line:27 char:13
+ $response = Invoke-RestMethod -Uri $assetUrl -Headers $JiraHeaders -M ...

 

Next challenge will be just exporting the name and display value to CSV but I can't get past this query issue first.

1 answer

0 votes
Dave Menconi
Contributor
August 7, 2023

At the risk of stating the obvious, it's getting hung up "IT" having "assets" after it. It seems to accept that the string 'IT Assets' have quotes around it but it just doesn't like "assets" coming after "IT". 

 

My advice is to use CURL or Postman to do the call and THEN translate it into the right Powershell syntax once you get the right return value. 

 

Dave

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events