Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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
Derek Fields Community Leader Dec 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.

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

Hi @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. 

Derek Fields Community Leader May 08, 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.

Thanks for the reply @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. 

Derek Fields Community Leader May 08, 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.

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. 

Derek Fields Community Leader May 08, 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. 

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

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
Answer accepted
Derek Fields Community Leader Dec 31, 2019

I reported it to them.

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

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
Derek Fields Community Leader Dec 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. 

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...

0 votes
Derek Fields Community Leader Dec 30, 2019

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

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...

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..

Have you tried with v3? Does it work?

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

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you