Forums

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

AQL - REST API - PHP Request - Params ignored

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.
March 10, 2023

Hi everyone! Hope you're all fine,

 

I'm trying to perform some automations over my Jira and right now I'm using PHP to perform an API REST call to return ASSETS

The documentation I use is this: AQL API REST 

The PHP code sample given in the documentation uses the Unirest library 

 

Anyway, this is the first time I try to perform and API call using PHP

I have done this before in Python 3 and have worked (using the Requests library)

The PHP project that I'm working with it uses the CURL setpot function to perform API calls

 

So, this is the situation, and current code:

Situation: I have an ASSET called Books, and there are over 25 of it, so, I have to use the PAGE param (because AQL API calls only retrieve 25 ASSETS, starting in PAGE 1) and iterate until I get all of the Books

Current code: The logical is right, and the PAGE param increases with each iteration and stops when reach the total number of Books, but, the API call ignores the param, so, the PAGE 1 is retrieved multiple times...

The code (I'm not putting the while cycle that I use to not make it longer, just the API call)

$assets_page = 1;

$ch = curl_init();

curl_setopt_array($ch, array

(
CURLOPT_URL => 'https://api.atlassian.com/jsm/assets/workspace/xxxx-xxxx-xxxx-xxxx/v1/aql/objects?qlQuery=objectSchemaId=1%20AND%20objectTypeId=1',
CURLOPT_USERPWD => 'username:token',
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "{\"page\":".$assets_page."}",
  CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
CURLOPT_RETURNTRANSFER => true            
 )
);

$result = curl_exec($ch);

curl_close($ch);
$decoderesult = json_decode($result);
print_r($decoderesult);  

If anyone has any idea of how to make, it would be quite apreciatte it

 

Thanks in advance

Best regards,

1 answer

1 accepted

1 vote
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.
March 16, 2023

I found the solution 

If anyone interested, the thing was to

  • delete the CURLOPT_POSTFIELDS
  • add the parameters in the URL after a & and using = instead of : like
$assets_page = 1;

$ch = curl_init();
curl_setopt_array($ch, array
(
   CURLOPT_URL => 'https://api.atlassian.com/jsm/assets/workspace/xxxx-xxxx-xxxx-xxxx/v1/aql/objects?qlQuery=objectSchemaId=1%20AND%20objectTypeId=1&page='.strval($assets_page),
   CURLOPT_USERPWD => 'username:token',
   CURLOPT_CUSTOMREQUEST => "GET",
   CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
   CURLOPT_RETURNTRANSFER => true             
 )
);

$result = curl_exec($ch);
curl_close($ch);
$decoderesult = json_decode($result);
print_r($decoderesult); 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
atlassian, confluence, loom, atlassian intelligence, ai notes, ai-powered meeting notes, atlassian community events, ace, confluence ai, loom ai integration, ai note-taking, atlassian ai features, team '25, atlassian live learning, confluence automation

Unlock AI-powered meeting notes: Join our live learning session! 📹

Did you catch the news at Team ‘25? With Loom, Confluence, Atlassian Intelligence, & even Jira 👀, you won’t have to worry about taking meeting notes again… unless you want to. Join us to explore the beta & discover a new way to boost meeting productivity.

Register today!
AUG Leaders

Atlassian Community Events