RESTful endpoint
Jira has native support for loading worklogs via REST, e.g. by searching for issues using JQL and including worklog
field in fields
request param, see /api/2/search.
Since Jira 6.4 there are three JQL clauses to limit result set to issues that have relevant worklogs: worklogAuthor
, worklogComment
and worlkogDate
. See Advanced Searching - Fields reference.
For worklogDate
valid formats include: 'YYYY/MM/DD'
, 'YYYY-MM-DD'
, or a period format e.g. '-5d'
, '4w 2d'
, or date function, e.g. endOfDay()
for Today
.
For worklogAuthor
username or membersOf()
can be used.
So, request can look like the following:
GET /rest/api/2/search?fields=*all&jql=filter=10001 and worklogDate > '2016-03-01' and worklogDate < endOfDay() and worklogAuthor in membersOf("jira-developers")
Then response JSON can look like:
{ "expand" : "schema,names",
"issues" : [{ "expand" : "editmeta,renderedFields,transitions,changelog,operations",
"fields" : { "worklog" : { "maxResults" : 2,
"startAt" : 0,
"total" : 2,
"worklogs" : [ { "author" : { "active" : true,
"avatarUrls" : { "16x16" : "http://localhost:2990/jira/secure/useravatar?size=small&avatarId=10142",
"48x48" : "http://localhost:2990/jira/secure/useravatar?avatarId=10142"
},
"displayName" : "admin",
"emailAddress" : "[email protected]",
"name" : "admin",
"self" : "http://localhost:2990/jira/rest/api/2/user?username=admin"
},
"comment" : "test",
"created" : "2013-10-16T17:56:32.887+0200",
"id" : "10012",
"self" : "http://localhost:2990/jira/rest/api/2/issue/10001/worklog/10012",
"started" : "2013-10-19T00:00:00.000+0200",
"timeSpent" : "1h",
"timeSpentSeconds" : 3600,
"updateAuthor" : { "active" : true,
"avatarUrls" : { "16x16" : "http://localhost:2990/jira/secure/useravatar?size=small&avatarId=10142",
"48x48" : "http://localhost:2990/jira/secure/useravatar?avatarId=10142"
},
"displayName" : "admin",
"emailAddress" : "[email protected]",
"name" : "admin",
"self" : "http://localhost:2990/jira/rest/api/2/user?username=admin"
},
"updated" : "2013-10-16T17:56:32.887+0200"
},
{ "author" : { "active" : true,
"avatarUrls" : { "16x16" : "http://localhost:2990/jira/secure/useravatar?size=small&avatarId=10142",
"48x48" : "http://localhost:2990/jira/secure/useravatar?avatarId=10142"
},
"displayName" : "admin",
"emailAddress" : "[email protected]",
"name" : "admin",
"self" : "http://localhost:2990/jira/rest/api/2/user?username=admin"
},
"comment" : "test",
"created" : "2013-10-16T17:56:33.075+0200",
"id" : "10013",
"self" : "http://localhost:2990/jira/rest/api/2/issue/10001/worklog/10013",
"started" : "2013-10-14T00:00:00.000+0200",
"timeSpent" : "4h",
"timeSpentSeconds" : 14400,
"updateAuthor" : { "active" : true,
"avatarUrls" : { "16x16" : "http://localhost:2990/jira/secure/useravatar?size=small&avatarId=10142",
"48x48" : "http://localhost:2990/jira/secure/useravatar?avatarId=10142"
},
"displayName" : "admin",
"emailAddress" : "[email protected]",
"name" : "admin",
"self" : "http://localhost:2990/jira/rest/api/2/user?username=admin"
},
"updated" : "2013-10-16T17:56:33.075+0200"
}
]
} },
"id" : "10001",
"key" : "TIME-2",
"self" : "http://localhost:2990/jira/rest/api/2/issue/10001"
}
],
"maxResults" : 50,
"startAt" : 0,
"total" : 1
}
Caution, worklog returned contains only first 20 worklogs per issue (see JRA-34746), and is not filtered according to specified worklogDate
and worklogAuthor
queries. It is your responsibility to load all worklogs per issue, using /rest/api/2/issue/{issueIdOrKey}/worklog endpoint, and filter out worklogs that do not match your criteria, see answers for help.
Note, alternatively you can see /api/2/worklog for massive loading worklog without issues data.
Before Jira 6.4
Since plugin version 2.6 you can use the same JQL search REST api but with workedIssues()
JQL function provided by the plugin, e.g. "key in workedIssues(fromDate, toDate, userOrGroup)" clause, to limit result set to issues with relevant worklogs only.
E.g. http://localhost:2990/jira/rest/api/2/search?jql=key in workedIssues("2013/10/14","2013/10/14","jira-developers")&fields=worklog
Caution, as above, worklog returned contains only first 20 worklogs per issue, and is not filtered according to specified worklogDate
and worklogAuthor
queries.
Plugin REST endpoint
Since plugin version 2.3.10, with timesheet plugin installed, it is possible to get worklogs in json format including minimum issue data.
E.g. with the url /rest/timesheet-gadget/1.0/raw-timesheet.json?moreFields=creator&moreFields=created, it will return:
{
"worklog": [
{
"key": "TIME-1",
"summary": "Hocus Focus Problem",
"entries": [
{
"id": 10014,
"comment": "test",
"timeSpent": 21600,
"author": "admin",
"authorFullName": "admin",
"created": 1458477642089,
"startDate": 1457910000000,
"updateAuthor": "admin",
"updateAuthorFullName": "admin",
"updated": 1458477642089
}
],
"fields": [
{
"label": "2013-03-12T09:45:35+0100",
"value": "created"
},
{
"label": "admin",
"value": "creator"
}
]
}
}
It accepts the following parameters
targetUser
- optional username,targetGroup
- optional group name, e.g. jira-users,startDate
- optional begin date in Jira date picker format, e.g.01/Jun/2012
, or in ISO date format, e.g.2012-06-01
,endDate
- optional end date, format is the same,projectid
- optional, e.g. 10001 (not project key!),filterid
- optional,moreFields
- optional.
If nothing is specified it behaves like report, displays data a week before current day for currently logged in user.
Dates in response are UNIX time - milliseconds since 01/01/1970
; timesSpent is in seconds.
See also issue#269
Export to CSV
Since version 2.9.8.3 and 3.0.8.3 it is possible to export raw worklogs in CSV format, similarly to Excel view, by using CSV View link in Time Sheet report or composing link basing on export link from Timesheet gadget, and replacing htmlExport url parameter with csvExport, e.g.:
http://localhost:2990/jira/rest/timesheet-gadget/1.0/timesheet.json?csvExport=true&weekends=true&targetUser=admin&showDetails=true&reportingDay=2&groupByField=customfield_group&moreFields=reporter&moreFields=status&moreFields=timespent&moreFields=timetracking&numOfWeeks=1&offset=0&sum=day