1

I'm trying to do this with powershell, but I'm getting 400 errors:

$RESTURL = 'https://mycomp.atlassian.net/rest/api/latest/issue/PROJ-61'
$body = '{"fields":{"assignee":{"name":"me"}}}'
$restcreds = [System.Convert]::ToBase64String(
[System.Text.Encoding]::ASCII.GetBytes(('me' + ":" + 'mypass123'))
)
$httpheader = @{Authorization = "Basic $restcreds"}
$restParameters = @{
Uri = $RESTURL;
ContentType = "application/json";
Method = "PUT";
Headers = $httpheader;
Body = $body;
}
Invoke-RestMethod @restParameters

If I remove "body" from the request and change it to a get I get back data successfully. It seems I just get modify the ticket

red888
  • 27,709
  • 55
  • 204
  • 392

1 Answers1

1

If you get a 400 (bad request), then that means something is wrong in your request body.

The response body will contain a more detailed error message and will make it clear what you have to fix.

Without the error message, I can only make a guess: I'm not sure if setting assignee to "me" works, unless "me" really is the name of a user. What happens if you try with a complete username or if you use "key" instead of "name"?

The fact that a GET request works fine shows that your credentials are correct, so it's not an authentication problem.

GlennV
  • 3,471
  • 4
  • 26
  • 39
  • There was nothing wrong with my request body, the issue was that an assignee of "me" didn't exist (I had a typo). And I found this SO question explaining how to get PS to output the request body (which is how I discovered the error) http://stackoverflow.com/questions/18771424/how-to-get-powershell-invoke-restmethod-to-return-body-of-http-500-code-response – red888 Aug 10 '16 at 15:35