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.