Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Invoke-WebRequest Bad Request using Rest API


I'm trying to get the rawcontent using jira rest api using powershell.

(Invoke-WebRequest -credentials get-credential "").rawcontent

However, after running this script I get Bad Request even when I enter my credentials after getting prompted


Invoke-WebRequest : The remote server returned an error: (400) Bad Request.
At line:1 char:2
+ (Invoke-WebRequest -Credential get-credential "https://solutions.frae ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke
-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWe

Has anyone encountered this before? The pretty sure the account I used is correct as I used it to login to jira but it doesn't work when I run this script. Main reason for creating this script is I want to get the output of the Issue Keys so I can use it as the parameters for the other script I used.

1 answer


Sorry to kick a two year old post. Hopefully you got your answer by now... but since this is pretty high on the most view yet unanswered questions, it's a slow day, and rawcontent had me curious... so here goes:

400 Bad Request means Atlassian doesn't like the way your call is formatted. If it were your credentials, it would definitely return 401 Unauthorized.

From what I can tell, you're missing a few things Atlassian is expecting. First is the Method... should be Get in this case. Your are also missing a couple Headers: Accept and Authorization (which should replace your -Credential tag)... You can't just pass PSCredentials. You need to use a header to tell them you're using Basic auth and you'll need to encode the values as Base64... and use api version 3... 

Give this a go:

$cred = Get-Credential
$Base64Cred = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $cred.GetNetworkCredential().UserName,$cred.GetNetworkCredential().Password)))
$server = ''
$jql = "Project = `"TEST Project`""
#remember to place a ` in front of all " characters

$responce = Invoke-WebRequest "$server/rest/api/3/search?jql=$jql" -Headers @{"Authorization" = "Basic $Base64Cred"; "Accept" = "application/json"} -Method 'Get'

Works for me. Many thanks!

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events