Hi,
I am looking for the API from where I can fetch work-logs of all the users under the ADMIN account.
I want to generate a report having details :
Please share the reference API asap.
Thanks & Regards,
Rashi
Hi @Rashi Goyal
You seem to contradict what you're looking for.
To me work logs are the time that a user has logged against various issues, but then in your report you only mention user-specific info. Using the following API call
rest/api/3/user/search?query=%
will return all users that you have permissions to view. It will return the accountId and dispayName for each user. The other items are not available (project manager and skill set are not part of Jira data)
Hi @Warren ,
Thanks for the answer.
I want to generate a report where I can list user and their time logged for the particular day.
Like User, A logged 7 hrs for the particular day.
So may I consider the above-mentioned solution for the same? Please confirm
Rashi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Rashi Goyal
Okay, I now understand what you're trying to do.
The API query that I gave above could be used to get the list of all users, or you can just supply the list.
If you use Tempo (Jira's time tracking app) then getting logs is quite simple, you use the following API call
https://api.tempo.io/core/3/worklogs/user/UserID?from=StartDate&to=EndDate
where the dates have the format yyyy-MM-dd
If you don't use Tempo, then you need to crawl through the history of each ticket to get the details. You'll set up an API call and include expand=changelog which gives you access to the history - you will then need to work through each history checking for logged time and build up each user's count.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Warren ,
I am not able to get the records of a particular date that I am passing. Please check my code-shared below:
$url = "https://netsmartz.atlassian.net/rest/api/2/search";
$r = '{
"jql": "project = NFLTV AND worklogDate=2020-09-29",
"maxResults": 1,
"fields": [
"summary",
"status",
"assignee",
"worklog"
]
}';
$this->curl_method($url, $r);
die('------');
Here, the worklogDate filter is not working. Rest is working fine for me. Please suggest the solution for the same. I am using POST for this.
Thanks in advance
Rashi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Rashi Goyal
Firstly, why are you using POST? You're just querying data, so it should be a GET. POST is used when creating or editing an issue.
Your date should be in double quotes (although it seems to be okay without), so
"jql": "project = NFLTV AND worklogDate="2020-09-29""
What you have in the "jql" section should work perfectly if you try it in the Issue Navigator within Jira - if it doesn't work there, you will at least get a meaningful error message
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am using query
This is giving me an error
tdClass Object ( [errorMessages] => Array ( [0] => No content to map to Object due to end of input ) )
Please suggest if I am doing something wrong.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Rashi Goyal
The JQL part usually uses AND instead of &, although that does seem to work.
I believe that fields=worklog is causing your error, it should be expand=changelog as stated above.
By default maxResults is 50 (I think), you don't really need to restrict it 1. You would typically use this parameter if you wanted more than 50, up to the maximum of 100.
Try the simplest query first and then build it up, so start with
https://netsmartz.atlassian.net/rest/api/2/search?jql=project=NFLTV
and if it works, then add the bit to filter on the date
https://netsmartz.atlassian.net/rest/api/2/search?jql=project=NFLTV AND worklogDate=2020-09-29
and then add the bit to get the history
https://netsmartz.atlassian.net/rest/api/2/search?jql=project=NFLTV AND worklogDate=2020-09-29&expand=changelog
That way you will know which section is causing the error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Warren ,
Thanks for the prompt reply and help.
Please explain that when using this
https://netsmartz.atlassian.net/rest/api/2/search?jql=project=NFLTV AND worklogDate=2020-09-29
which field will describe that this worklog data is of the particular date i.e. 29 as mentioned in our query.
Because I am getting complete details.
Thanks,
Rashi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Rashi Goyal
My previous reply suggested you slowly build up the API call to see where it's going wrong, which you haven't commented on here.
First get the call working, without worrying about the details of what is returned. When you are able to run the full API call successfully
https://netsmartz.atlassian.net/rest/api/2/search?jql=project=NFLTV AND worklogDate=2020-09-29&expand=changelog
then we can discuss the details of what is being returned
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Warren,
Ya, I am able to call the API successfully with the step wise guide you mentioned in the previous comments. Thanks for that
Please let me know what to do further.
Regards,
Rashi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Rashi Goyal
Okay good, that's progress ;-)
If you run the call
https://netsmartz.atlassian.net/rest/api/2/search?jql=project=NFLTV AND worklogDate=2020-09-29&expand=changelog
part of the JSON returned will be histories. You will need to loop through all the histories checking for items like
{
"field": "timespent",
"fieldtype": "jira",
"fieldId": "timespent",
"from": "4500",
"fromString": "4500",
"to": "6300",
"toString": "6300"
},
All times are in seconds, here the original amount of time logged (4500) is 1h 15m and it changed to (6300) 1h 45m, so 30m was logged. When you find an entry like this, you can check the displayName and created fields to get who logged the time and when they did.
Even though you've passed a date for worklogs, for a specific issue, it is giving the whole history so you will need to filter out time logged on other days.
I hope this is clear and helps you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Warren ya now I am able to create a clear picture.
Stuck in one thing i.e. from & to fields. For testing purpose, I logged 2 hours in my task and the result I got is
[1] => stdClass Object
(
[field] => timespent
[fieldtype] => jira
[fieldId] => timespent
[from] => 135600
[fromString] => 135600
[to] => 142800
[toString] => 142800
)
from = 37.6666667
to = 39.6666667
So, total time logged = 2hrs that is correct but I also want to now that on what basis this from and to time is collected.
Rashi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Rashi Goyal
I'm pleased that you're seeing the numbers that you are expecting.
Unfortunately I don't understand your question - what do you mean by what basis?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I mean how do API collect the data of from and to variables.
As I have seen that sometimes from variable is empty.
Rashi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, okay, I understand your question now @Rashi Goyal
If you create a new ticket, then log some time against it, the from will be blank (empty) and the to will have the amount of time logged. From then on, each time a worklog is added, the from should have the value of the previous time and shouldn't be blank.
This applies to most items - if you assign the ticket to someone for the first time (or add a label or add a component or ...), the from would be blank as well
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Warren,
Please tell one thing that if I am using API with URL
Then this API will return me all the records in one go or pagination is working by default?
Means I want to ensure that if I will get all records of the master account in one go or I have to add something custom.
Please help me out in this scenario.
Thanks
Rashi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Pagination is required to get all records, depending on your query and data.
By default, 50 records are returned at a time, but the API call that you've given has maxResults=2, so you will only get 2 records back.
I would suggest that :
You need to check the initial bit of JSON for the fields maxResults (tells you how many records have been returned) and total (tells you how many records there are in total)
{"expand":"schema,names","startAt":0,"maxResults":50,"total":9065,"issues"
If total is less than or equal to maxResults then you wouldn't need to paginate, otherwise you would.
For pagination, you pass in the parameter startAt. As you will see, your first API call defaults to startAt=0, so your next call would need to set startAt to 0 + 50 (i.e. startAt=50) and the call after that startAt=100 etc.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Warren ,
I checked the result i.e.
[expand] => schema,names [startAt] => 0 [maxResults] => 7 [total] => 707
If I am using maxresult=2 I am getting total as 707 so that means I have to paginate. Right?
Can you please guide me how to add pagination ?
It will be done using some custom php standards or jira provide us the way to directly pass it to the url ?
URL : "https://netsmartz.atlassian.net/rest/api/2/search?jql=project=SKL&worklogDate=2020-09-30&expand=changelog&maxResults=2";
Please share how to add pagination.
Also one more requirement, I want to fetch the email id of the users as well.Please guide for that also.
I want to implement this asap. So, it will be good if you can share the answer asap.
Thanks
Rashi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Warren ,
Mentioned by you "fields=worklog" is not giving an error. It's a regular field in Jira API to get up to 20 worklogs from the issue.
I think Rashi took it from my answer to his duplicate topic: https://community.atlassian.com/t5/Jira-Software-questions/API-Reference-required-to-get-the-worklogs-of-all-the-users/qaq-p/1490596
The idea is to collect worklogs using search method instead of going one-by-one. The most issues in my projects have less than 20 worklog entries to it's enough to get them all. If there is an issue with more than 20 worklog entries, I'm doing another round of one-by-one collection. This hybrid method (search + one-by-one) is more efficient in terms of tool used as well as Jira API requests number.
And since Rashi asks for worklogs in my opinion going into changelogs is way too much to get the results (less efficient).
Best
Michael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Rashi Goyal
Yes you're correct, you will need to paginate if you have 707 total records. I'm not sure why you keep passing in maxResults=2, that would mean over 350 API calls! My previous answer described how to paginate
For pagination, you pass in the parameter startAt. As you will see, your first API call defaults to startAt=0, so your next call would need to set startAt to 0 + 50 (i.e. startAt=50) and the call after that startAt=100 etc.
But I'll expand on that for you.
Using the API query that you've supplied, I'll expand it to show you what you need to do. For your first call, you would use
https://netsmartz.atlassian.net/rest/api/2/search?jql=project=SKL&worklogDate=2020-09-30&expand=changelog&maxResults=50&startAt=0
For your next call, it would be
https://netsmartz.atlassian.net/rest/api/2/search?jql=project=SKL&worklogDate=2020-09-30&expand=changelog&maxResults=50&startAt=50
Then the next one would be
https://netsmartz.atlassian.net/rest/api/2/search?jql=project=SKL&worklogDate=2020-09-30&expand=changelog&maxResults=50&startAt=100
So you can see that with each successive call, the only change is startAt=xx, where xx increases by 50 each time because maxResults is set to 50. You will need to code your solution to keep increasing the startAt value until startAt > total.
Now for the user's ID, if you look at the screenshot below, each history has a section which lists the user that made the change, so you can get it from there without doing anything else
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Michael Raj
No that won't work! Since about 2017 Atlassian have limited the number of returned records. The absolute maximum you are able to get from one call is 100 records, but I believe that you need to have changed a setting within Jira and I didn't want to get into that with @Rashi Goyal at the moment. By default, the limit is set to 50, hence my description of getting 50 records at a time
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Warren thanks..
I got an idea that we have to iterate our loop to get this pagination done.
maxresult I was passing because I want to check the array structure.
Now, I am working as mentioned above.
One more thing @Warren I need the email-id & project manager of the user, not user id. How to achieve that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Rashi Goyal
Sorry, I have no idea what email-id is - if you mean the email address of the user, that is no longer available because of GDPR concerns.
Also project manager is not a field that I'm aware of - if this is a customfield that you have added, then you will need to know the field number, because customfields are referenced in the API with the format customfield_12345. If it is one of your customfields, you should be able to find it in the JSON returned from your API call
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Warren while using JIRA I think every user's e-mail address is linked.
So, don't we have any way out in API Calls to get the same?
If not the project manager then I think it is possible to get an assignee?
If yes please let me know
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Rashi Goyal
No you are able to get the user's displayName, see my screenshot further up.
Yes the field assignee is available
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.