Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Transition issue with worklog and comment using rest and powershell

Ulf Wüstefeld October 2, 2018

Hi,

 

i'm trying to transition an item to "Resolved" and everytime i get a HTTP 400 and i don't know why.

Can anybody give a hint what ist wrong with my json?

{
    "update": {
        "worklog": [{
            "add": {
                "started": "2018-10-02T06:00:00.000+0000",
                "timeSpent": "1m"
            }
        }],
        "comment": [{
            "add": {
                "body": "Bug has been fixed."
            }
        }]
    },
    "fields": {
        "customfield_10636": {
            "value": "yes"
        },
        "customfield_10533": [{
            "add": {
                "id": "10421"
            }
        }]
    },
    "resolution": {
        "id": "10000"
    },
    "transition": {
        "id": "5"
    }
}

As mentioned in the documentation HTTP 400 means that the transition does not exist, but when i fetch the transition data i get 8601 as id for transition and 5 as id for transition.to.

My skript (powershell):

$servicedeskheaders = @{ Authorization = 'Basic AUTHHEADER'}
$proburl = "https://SERVER/rest/api/2/issue/ISSUE/transitions?expand=transitions.fields"
try
{
    $transitiontotargetstatus='{"update":{"worklog":[{"add":{"started":"2018-10-02T06:00:00.000+0000","timeSpent":"1m"}}]},{"comment":[{"add":{"body":"Problem ist gefixt mit dem Release *EASY for Exchange 2.0.2* vom *06.09.2018*. [Download|https://extranet.easy.de/display/EASYforExchange/Downloads]"}}]},"fields":{"customfield_10636":{"value":"yes"},"customfield_10533":[{"add":{"id":"10421"}}],"resolution":{"id":"10000"}},"transition":{"id":"5"}}}'
    $updatedissue = (Invoke-RestMethod -uri $proburl -Headers $servicedeskheaders -Method POST -Body $transitiontotargetstatus -ContentType "application/json").id
    Write-Host ($updatedissue)
}
catch
{
    $ErrorMessage = $_
    Write-Error ($ErrorMessage)
}

AUTHHEADER, SERVER and ISSUE have to be replaced by basic authheader, jira server and issue.

Tested on https://jsonlint.com/ my json seems to be valid.

2 answers

1 accepted

0 votes
Answer accepted
Ulf Wüstefeld October 8, 2018

OK, i found out on my own.

Here is the solution:

The json has to look as follows:

{
    "transition": {
        "id": "8016"
    },
    "fields": {
        "customfield_10533": [{
            "id": "10421"
        }],
        "resolution": {
            "id": "10000"
        }
    },
    "update": {
        "worklog": [{
            "add": {
                "started": "2018-10-08T13:38:45.000+0000",
                "timeSpent": "1m",
                "timeSpentSeconds": 60
            }
        }],
        "comment": [{
            "add": {
                "body": "The Bug has been fixed"
            }
        }]
    }
}

as you can see, "fields" works without "update" while "comment" and "worklog" needs it.

This took me days and grew me gray hairs.

0 votes
Ulf Wüstefeld October 7, 2018

not needed any longer

Suggest an answer

Log in or Sign up to answer