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

Rest Api Add Worklog

Zack Peine July 31, 2013

I have looked at a number of posts here and can't seem to figure out what I'm doing wrong. I would like to use the Rest Api to add a worklog to an issue.

request:

resource: "/rest/api/2/issue/TEST-93/worklog"
method: POST
using Basic Authentication
requestbody: {\"worklog\":[\"add\",{\"timeSpent\":\"1m\",\"timeSpentInSeconds\":\"60\",\"comment\":\"integration test successful\"}]}}

I keep an getting "Unrecognized field \"update\"" error from the server.

I can create an issue without a problem, but can't seem to figure out the correct syntax for adding a worklog to an issue via the API.

Can anyone help? Thanks!

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
RambanamP
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.
July 31, 2013

the json string should be like this

{
    "self": "http://www.example.com/jira/rest/api/2.0/issue/TEST-1/worklog/10000",
    "author": {
        "self": "http://www.example.com/jira/rest/api/2.0/user?username=fred",
        "name": "fred",
        "displayName": "Fred F. User",
        "active": false
    },
    "updateAuthor": {
        "self": "http://www.example.com/jira/rest/api/2.0/user?username=fred",
        "name": "fred",
        "displayName": "Fred F. User",
        "active": false
    },
    "comment": "I did some work here.",
    "started": "2012-02-15T17:34:37.937-0600",
    "timeSpent": "3h 20m",
    "timeSpentSeconds": 12000,
    "id": "100028"
}

Zack Peine July 31, 2013

Thanks again, appreciate all the feedback. I copied and pasted your string and inserted my values except for the id. Since I'm trying to add a worklog, I don't believe an id exists yet. When I run it though, I'm getting: \"timeSpent\":\"A value is required for manual estimate adjustment\"}

I do have a value for timeSpent though: "timeSpent": "1m".
Any ideas? Thanks!

0 votes
ayyappa m August 8, 2014

String data = "{\"fields\":{\"worklog\":[\"add\",{\"timeSpent\":\"1m\",\"timeSpentInSeconds\":\"60\",\"comment\":\"integration test successful\"}]}}";

I am using the above JSON string to add new worklog to my JIRA ticket.

But, its throwing

status code [405], status message [Method Not Allowed]

Please help me updating the above JSON string.
0 votes
RambanamP
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.
July 31, 2013

i think you have to change the request body

check this

https://docs.atlassian.com/jira/REST/latest/#idp1978400

if you want to Updates an existing worklog entry using its JSON representation

https://docs.atlassian.com/jira/REST/latest/#idp1994144

Zack Peine July 31, 2013

Thanks for the response. I've been looking at the documentation and even found this post: https://answers.atlassian.com/questions/139686/how-to-log-work-then-resolve-issue-using-rest-api which is what I modeled my call after. I'm still unsure how I have to restructure the body of the request. Could you provide a simple example? Thanks.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events