Jira API Rest - Get issue worklog using query parameter "startedAfter"

Lara Gonzalez Villanueva December 30, 2019

Hi,

I have a problem when trying to use the API "GET rest/api/2/issue/{issueIdOrKey}/worklog" (I'm using Python). I would like to use the query parameter "startedAfter" but I'm finding some difficulties on using it, can you help me and tell me what I'm doing wrong?

The documentation says:

startedAfter

integer

The worklog start date and time, in UNIX timestamp format, after which worklogs are returned.

Format: int64

I converted the date ['2019', '12', '10', '00', '00'] to unix timestamp format using:

dt = datetime.datetime(2019, 12, 10, 00, 00)

unix_tm = (time.mktime(dt.timetuple()))

And then create the url:

https://{host}/rest/api/2/issue/{issue_key}/worklog?jql=startedAfter=1575932400

But I always get all the worklogs and not just those after that date...

I also tried:

https://{host}/rest/api/2/issue/{issue_key}/worklog?startedAfter=1575932400

Thank you so much in advance! 

 

Lara

4 answers

2 accepted

0 votes
Answer accepted
C_ Derek Fields
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.
December 31, 2019

I reported it to them.

Lara Gonzalez Villanueva January 2, 2020

Thank you Derek! Do you have any link or reference? It would be very useful to follow up the resolution!

Giuseppe D_Angelo February 11, 2020

I am facing the same issue and I am using the postman collection provided in the "developer guideline pages" (v2 and v3).

Is it possible to have the reference link of the raised bug? 

It will be very useful.

0 votes
Answer accepted
C_ Derek Fields
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.
December 30, 2019

I tried it in my Cloud environment. It doesn't work correctly for me either. It appears that this is a bug that should be opened with Atlassian.

Lara Gonzalez Villanueva December 31, 2019

Thank you so much Derek! Do you know how can I inform Atlassian about this bug?

Rakesh15 May 8, 2020

Hi @C_ Derek Fields ,

Could you please let me know,  how can I access JIRA Rest API by impersonating a user request. A request from user should go to a service. Service should use admin rights to access API and fetch the details. 

C_ Derek Fields
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.
May 8, 2020

I don't understand the question. When you access a REST API, you need to authenticate, either through Basic authentication or by following the OAUTH flow, which requires a login sequence through a URL. The login credentials that you use will indicate the user that is making the REST call. 

On server, you could write a custom REST call that would allow a user to make the call and then execute the request as an admin-privileged user. You can't do that on Cloud.

Rakesh15 May 8, 2020

Thanks for the reply @C_ Derek Fields . 

I read it somewhere that basic authentication is deprecated. Can I still use it. 

Please read my below to understand my scenario. 

User submits a request to create an issue in jira board. Since user doesn't have account in jira. I want to create a rest api which will receive the users request and then uses admin credentials and make a request to jira rest api to create an issue. This is what I am trying to achieve. 

 

However, I am facing problems here. I have admin account in jira. When I login in browser  I can see JSessionId. Now when I am passing my user name or email Id with password (which is my windows password) basic authencarion is failing. 

Could you please be do kind to help me. 

C_ Derek Fields
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.
May 8, 2020

You can still use basic authentication. You need to pass a header that is

Authentication: Basic <base64 encoded token>

The encoded token is formed by taking the string <username>:<password> and base64 encoding it. 

You can do this in Powershell with following:

$Text = 'username:password'
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($Text)
$EncodedText =[Convert]::ToBase64String($Bytes)
$EncodedText

This will show you the token. 

I hope that this helps.

Rakesh15 May 8, 2020

Thanks for such quick reply.  I will try this.

One last question. My organization has hosted jira in cloud looks like. Url looks something like 

https://gojira.companyname.cloud/jira 

 

Will this still work, as you mentioned it wouldn't work in cloud? 

If not, cannot I use oauth and do some impersonation. If so how can that be achieved. 

C_ Derek Fields
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.
May 8, 2020

Instead of using a password in the cloud, you need to generate an API token and use that as the password, following the same logic as above. You create an API token by going to your profile and looking under Security. 

I am not an expert in OAUTH implementation. It requires a web server on your end to provide the user with an authentication dialog. 

Rakesh15 May 8, 2020

@C_ Derek Fields , sorry to say but the basic authentication is failing. Its giving 500 internal server error. Could you please help me.

Rakesh15 May 8, 2020

I am helpless now. First of all, I am not seeing an option to generate API token in my JIRA board under profile. I even searched in google. Could you please tell me why I do not have option to generate API token. I am an admin.

0 votes
C_ Derek Fields
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.
December 30, 2019

Try multiplying the timestamp by 1000 to change it from seconds to milliseconds. 

Lara Gonzalez Villanueva December 30, 2019

What do you mean? 

Using:

https://{host}/rest/api/2/issue/{issue_key}/worklog?startedAfter=1575932400000

Instead of:

https://{host}/rest/api/2/issue/{issue_key}/worklog?startedAfter=1575932400

 ?

I'm still getting all the worklogs...

Like m_schnabl likes this
cfsfonseca July 8, 2020

I'm having the same issue but I think the problem here is that we're using v2 of the API.

"startedAfter" seems to have only been introduced from v3..

Lara Gonzalez Villanueva August 5, 2020

Have you tried with v3? Does it work?

cfsfonseca August 5, 2020

I didn't try with v3 @Lara Gonzalez Villanueva as it would be too much trouble asking my company to upgrade..

I ended up using the tempo API to achieve what I wanted but you must have the tempo plugin installed:

https://www.tempo.io/server-api-documentation/timesheets#operation/searchWorklogs

Hope this helps,

Carlos

Lara Gonzalez Villanueva August 5, 2020

Thank you!

m_schnabl
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 8, 2024

milliseconds worked. Thanks!!!!

0 votes
C_ Derek Fields
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.
December 30, 2019

You don't specify whether you are on Cloud or Server. The APIs for each are different. I can see, though, from the documentation that you are using Cloud, which makes a different.

In any case, try using:

https://{host}/rest/api/2/issue/{issue_key}/worklog?startedAfter=1575932400

leave out the "jql=". That should return what you want. 

Lara Gonzalez Villanueva December 30, 2019

Hi Derek,

Thanks for your answer! I guess I'm using Cloud (anyway I'm not completely sure...). As I wrote on my comment I have already tried that option, without "jql=", but the response is the same, I get all the worklogs...

Suggest an answer

Log in or Sign up to answer