addWorklog methods return "cannot deserialize WorklogJsonBean" error

Hi,
I want to add a new worklog to an issue:

const issueId = 1000
AP.request(`/rest/api/3/issue/${issueId}/worklog`, {
    type: 'POST',
    contentType: 'application/json',
    headers: { 'Accept': 'application/json' },
    data: {
      "timeSpentSeconds": 12000,
      "visibility": {
        "type": "group",
        "value": "jira-developers"
      },
      "comment": {
        "type": "doc",
        "version": 1,
        "content": [
          {
            "type": "paragraph",
            "content": [
              {
                "text": "I did some work here.",
                "type": "text"
              }
            ]
          }
        ]
      },
      "started": "2019-11-19T12:25:52.254+0000"
    }
  })

The payload is copied directly from the example in the documentation - api-rest-api-3-issue-issueIdOrKey-worklog-post. (I have tried enter here full link to the documentation, but then I was not able to create this topic with message “Sorry you cannot post a link to that host”, which I do not understand why, when the domain was atlassian com :frowning: ).

But this request returns error:

Can not deserialize instance of com.atlassian.jira.issue.fields.rest.json.beans.WorklogJsonBean out of START_ARRAY token\n at [Source: com.atlassian.plugin.connect.plugin.auth.scope.InputConsumingHttpServletRequest$1@3a74eec1; line: 1, column: 1]

It seems, that the JSON payload has something missing or so, but as I stated, it is exactly the same as in the docs, so what could be wrong?

I have tried another approach. With help of “OAuth 2.0 (3LO) for apps” asked for app access token and id of our Jira cloud site and tried to add a new worklog with an external application:

POST https://api.atlassian.com/ex/jira/<id of our Jira cloud site>/rest/api/3/issue/10000/worklog
Authorization: Bearer <myAccessToken>
Content-Type: application/json

{
  "timeSpentSeconds": 1200,
  "comment": {
    "version": 1,
    "type": "doc",
    "content": [
      {
        "type": "paragraph",
        "content": [
          {
            "type": "text",
            "text": "I did some work here."
          }
        ]
      }
    ]
  },
  "started": "2019-11-23T18:35:00.000+0000"
}

And this works fine. So what is the difference between these two approaches and why the first one does not work? It’s really weird.

2 Likes