I've read just about ever bit of documentation I can find however I'm unable to get this to work. I'm using powershell to attempt a REST-API GET method;
# Create username / API key pair, then encode it
$baseString = "first.last@mydomain.com:<myAPIKey>"
$baseBytes = [System.Text.Encoding]::Unicode.GetBytes($baseString)
$base64 = [System.Convert]::ToBase64String($baseBytes)
# Build headers
$authHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$authHeaders.Add('Basic', ('Basic {0}' -f $base64))
$authHeaders.Add('Accept', 'application/json')
# Call Rest API
Invoke-RestMethod -Uri "https://mydomain.atlassian.net/rest/api/3/issue/TS-1000" -Method Get -Headers $authHeaders
Each time I'm getting a "Invoke-RestMethod : The remote server returned an error: (404) Not Found." error.
URL works without issue or a 404 error in a browser as seen:
Hi Jeret,
I see that you're using Powershell in order to try to make a REST API call to a Jira Cloud site, but that this is not working as expected. I took a closer look at your steps to make this work and I believe I see the problem here.
You are using the base64 encoded string of emailaddress:API_Token, however the way you encode that string is technically different from the way we state to encode it in our Basic Auth for REST APIs documentation.
To highlight this difference I used an example string of 'first.last@mydomain.com:<myAPIKey>' and in the first example I used the documented method, and the second I used your method. In order for this to work correctly I'd expect the same output
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:\Users\IEUser> $Text = `first.last@mydomain.com:<myAPIKey>'
PS C:\Users\IEUser> $Bytes = [System.Text.Encoding]::UTF8.GetBytes($Text)
PS C:\Users\IEUser> $EncodedText = [Convert]::ToBase64String($Bytes)
PS C:\Users\IEUser> $EncodedText
Zmlyc3QubGFzdEBteWRvbWFpbi5jb206PG15QVBJS2V5Pg==
PS C:\Users\IEUser>
PS C:\Users\IEUser>
PS C:\Users\IEUser> $baseString = "first.last@mydomain.com:<myAPIKey>"
PS C:\Users\IEUser> $baseBytes = [System.Text.Encoding]::Unicode.GetBytes($baseString)
PS C:\Users\IEUser> $base64 = [System.Convert]::ToBase64String($baseBytes)
PS C:\Users\IEUser> $base64
ZgBpAHIAcwB0AC4AbABhAHMAdABAAG0AeQBkAG8AbQBhAGkAbgAuAGMAbwBtADoAPABtAHkAQQBQAEkASwBlAHkAPgA=
But as you can see, your example is encoding this string much differently. I suspect this might be due to the use of the unicode.getbytes instead of the UTF8 we are expecting here. I also tried with double quotes instead of single, but that doesn't seem to make a difference.
Try instead to use this method for encoding your credentials:
$Text = ‘user@example.com:api_token_string’ $Bytes = [System.Text.Encoding]::UTF8.GetBytes($Text) $EncodedText = [Convert]::ToBase64String($Bytes) $EncodedText
The use of the incorrect credentials here would certainly be a plausible explanation for the 404 error you see here. Try that and let me know the results.
Andy
Andy, thanks for taking the time to write and test with such a detailed response. I really appreciate it.
I also found another thread that used `UTF8` instead of Unicode. The interesting thing is I ran a `Compare-Object` on both of those outputs and saw no difference. None the less, I did get things working with the `UTF8` method.
Odd, but glad I got it working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We are facing the same issue as well (404) Not Found.
We already switched the encoding to UTF8 but the issue still persist.
One difference I noticed is in our case we use username and password instead of API token.
$basicAuth = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$($JiraUser):$JiraPwd"))
$headers = @{"Authorization" = $basicAuth
"Content-Type" = "application/json"}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, My bad!
The rest api url had a mistake:, there was an additional /jira included.
May be I just copy pasted from an example and did not really validate the ling
https://jira.test.com/jira/rest/api/latest/issue/TVM-xx/remotelink
https://jira.test.com/rest/api/latest/issue/TVM-xx/remotelink
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.