Forums

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

History array for the specific date only using API Call

Rashi Goyal October 16, 2020

Hi Team,

I am using an API where I am getting a log of all the dates. 

URL I am using https://xyz.atlassian.com/rest/api/2/search?jql=&startAt=".$s."&expand=changelog

This URL is giving me all the information but I have to loop a number of times for this because pagination work in slots of 50 as checked.

Do we have any way of passing the date filter as well in the URL so that we get the records only for that specific date?

@Warren you guided me pretty well on this. Please clear this confusion as well it would be a great benefit for me.

Anyone else knows how to proceed please respond.

Thanks,

Rashi

1 answer

1 accepted

0 votes
Answer accepted
Mehmet A _Bloompeak_
Atlassian Partner
October 16, 2020

Hi @Rashi Goyal ,

If you want to narrow down the change history by date, unfortunately it is not possible. But below might help you a little:

Default page size is 50, but it can be modified with maxResults parameter up to 100.

https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#expansion

Rashi Goyal October 16, 2020

@Mehmet A _Bloompeak_ thanks for answering that means date filter will not work right?

We have to loop over all records 

Mehmet A _Bloompeak_
Atlassian Partner
October 16, 2020

Date filter will work for issue creation date, resolution date etc. It will not work for change log creation date.

Rashi Goyal October 16, 2020

@Mehmet A _Bloompeak_ what if I want to fetch the details of all the users along with their projects and the date on which they logged the hours.

Like :

[created] => 2020-09-03T22:17:26.607+0530
                                            [items] => Array
                                                (
                                                    [0] => stdClass Object
                                                        (
                                                            [field] => timeestimate
                                                            [fieldtype] => jira
                                                            [fieldId] => timeestimate
                                                            [from] => 
                                                            [fromString] => 
                                                            [to] => 0
                                                            [toString] => 0
                                                        )

                                                    [1] => stdClass Object
                                                        (
                                                            [field] => timespent
                                                            [fieldtype] => jira
                                                            [fieldId] => timespent
                                                            [from] => 
                                                            [fromString] => 
                                                            [to] => 1800
                                                            [toString] => 1800
                                                        )

                                                    [2] => stdClass Object
                                                        (
                                                            [field] => WorklogId
                                                            [fieldtype] => jira
                                                            [from] => 
                                                            [fromString] => 
                                                            [to] => 832981
                                                            [toString] => 832981
                                                        )

                                                )

Here created is the date on which user logged the hours. Right?

Now, the histories array is returning me the data of all the dates. I want that is their any way to pass date in URL so that this [created] field will only get the data of that particular date only?

I hope this is clear now. Please share your view

Thanks

Mehmet A _Bloompeak_
Atlassian Partner
October 16, 2020

No there is no way to pass the changelog created date from the rest api url. You must get all the changelog, parse and filter the ones you need.

Rashi Goyal October 16, 2020

Ok, thanks a lot! I am on a right track then

Rashi Goyal October 25, 2020
Mehmet A _Bloompeak_
Atlassian Partner
October 25, 2020

$url = "https://xyz.atlassian.net/rest/api/2/search?jql=project=" . $project['project_key'] . "&maxResults=100&startAt=0&expand=changelog";
$result = $this->curl_method($url);
$finalresult = json_decode($result);
echo"<pre>";print_r($finalresult);die;

Rashi Goyal October 26, 2020

@Mehmet A _Bloompeak_ Thank you I checked the above one is working fine.

I was looping in the chunks of 50 earlier & Now it will run on 100 ryt?

Only this much difference we can make in our call.

 

Mehmet A _Bloompeak_
Atlassian Partner
October 26, 2020

for ($m = 0; $m <= $finalresult->total; $m += 100) {
$url = "https://xyz.atlassian.net/rest/api/2/search?jql=project=" . $project['project_key'] . "&startAt=" . $m . "&maxResults=100&expand=changelog";
$result = $this->curl_method($url);
echo"<pre>";print_r($result);die;

}

Like Rashi Goyal likes this
Rashi Goyal October 26, 2020
Rashi Goyal October 26, 2020

@Mehmet A _Bloompeak_ 

please check my below mentioned query

Rashi Goyal October 26, 2020

@Mehmet A _Bloompeak_ 

Please check my code ;

I am getting around 3 lakh records using an API https://xyz.atlassian.net/rest/api/2/search?jql=&startAt=0&expand=changelog
After this, I am filtering my data and customizing it.
Basically, I want to generate a report where less than 8 hrs logged by the users are tracked.


<?php
public function getUserLogs() {
$this->db->truncate('work_logs_json');
$this->db->truncate('work_logs');

$filter_data_start = date('Y-m-d H:i', strtotime('2020-10-25 12:00'));
$filter_data_end = date('Y-m-d H:i', strtotime('2020-10-26 10:05'));

$getProjects = $this->Usermodel->getProjects();
//echo"</pre>";print_r($getProjects);die;
if (isset($getProjects)) {
foreach ($getProjects as $project) {
$url = "https://xyz.atlassian.net/rest/api/2/search?jql=project=" . $project['project_key'] . "&startAt=0&expand=changelog";
$result = $this->curl_method($url);
$finalresult = json_decode($result);
for ($m = 0; $m <= $finalresult->total; $m += 100) {
$url = "https://xyz.atlassian.net/rest/api/2/search?jql=project=" . $project['project_key'] . "&startAt=" . $m ."&maxResults=100&expand=changelog";
$result = $this->curl_method($url);
$this->Usermodel->saveRecords('work_logs_json', ['data' => $result]);
}
}
}
}
At this point when I am saving data to the DB I am getting an error
Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 2681144 bytes) in /var/www/html/pmo1/system/database/drivers/mysqli/mysqli_result.php on line 214

A PHP Error was encountered

Severity: Error
Message: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 2681144 bytes)
Filename: /var/www/html/pmo1/system/database/drivers/mysqli/mysqli_result.php
Line Number: 214

Although I am running this code using ssh only.

Please suggest any other way out to tackle this obstacle.

Rashi

Rashi Goyal October 27, 2020

@Mehmet A _Bloompeak_ & @Warren please guide on my above query.

Anyone else aware of any other way please post.

@jirasupport 

Thanks,

Rashi

Suggest an answer

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

Atlassian Community Events