For starters
I'm very new to the world of web requests, REST, and APIs, and only have limited experience with Powershell, so it may be that I'm missing something very obvious to the trained eye.
Situation
I can make a REST call in Postman, to our Jira Cloud instance, and the the results of a query to our knowledgebase.
Basically this URL:
https://MYSITE.atlassian.net/rest/servicedeskapi/servicedesk/1/knowledgebase/article?query=Skype
When trying to do the samething with Invoke-RestMethod in Powershell I keep getting a 401 Unauthorized response.
The things I've tried
Read through every hit on the first couple of pages on Google and Bing (because you never know), but haven't found anything that made it clear to me.
My code
Gracefully stolen from someone with a similar issue, who got it to work like this.
$user = [System.Text.Encoding]::UTF8.GetBytes("my.email@company.dk:MyApiToken")
$headers = @{Authorization = "basic" + [System.Convert]::ToBase64String($user)}
Invoke-RestMethod -Uri "https://MYSITE.atlassian.net/rest/servicedeskapi/servicedesk/1/knowledgebase/article?query=Skype" -Method GET -Headers $headers -ContentType "application/json"
Why Powershell?
I want to create a one-stop-script for creating new projects, and access to our instance is managed by groups in Azure AD. We already have a script for creating those groups, and this would be a continuation of that script.
NOTE:
This is just me learning. The GET call is just to help me get a better understanding of working with REST calls in Powershell.
Update:
I woke my laptop up from sleep mode, noticed a capital B in "Basic", changed it to lower case, looked at headers in Postman, noticed that the Authorization header had "Basic" with a capital B in the value, changed it back to capital B in my script.
Then I ran the script to remind myself what error message I was getting, and now it works.
I don't know why, but for some reason it works.
Hey @Rune Rasmussen ,
Glad you figured this one out and a big thank you for sharing the solution you found.
And I too am not 100% sure on what is happening here but the third party applications are doing some case conversion in the background causing a conflict for the auth header and its a mind your p's and q' moment, but I had helped on a similar case with postman with a similar issue on case sensitivity in "basic" depending on whether you're currently logged in or not, and I wanted to link it here as a reference point in case anyone else is hitting the same issue:
Regards,
Earl
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.