Forums

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

Use Powershell with Jira REST API - error: (403) Forbidden

alex.kaushansky
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 9, 2020

I am trying to use Powershell to connect Jira REST API and find a way to add few hundreds users to their groups.

First thing, i am trying to get accountId for users and i run a simple command:

GET /rest/api/3/groupuserpicker?query=user@domain.ext

in powershell this command failed with 

Invoke-WebRequest : The remote server returned an error: (403) Forbidden.

but in the very same PS window this very same command works with CURL

 

What am i missing with PS? Does PS works with API token or do i need to do some other kind of authentication?

 

Thanks.

 

2 answers

0 votes
Sunny Ape
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 13, 2020

In PS, Invoke-WebRequest and Invoke-RestMethod support all of Jira's authentication methods like basic or token.

Just note that they are both sensitive to self-signed SSL certificates whereas curl isn't. Self-signed SSL certs are common with companies that have their own Jira Server and don't want / need to pay for 'real' certification from a certifying entity.

0 votes
Italo Qualisoni [e-Core]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 9, 2020

Hi @alex.kaushansky ,

 

I had this issue in the past, it seems that PS curl has some sort of a symbolic link to Invoke-WebRequest , and you need to include the header in a different way.

 

I couldn't find a way to do it in a single command, and I got this from this reddit 

$Uri = "https://jira.atlassian.com/rest/api/3/groupuserpicker?query=user@domain.ext"
$Username = "username"
$Password = "apitoken"

$Headers = @{ Authorization = "Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Username,$Password))) }


curl -Uri $Uri -Headers $Headers

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events