Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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'

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

Send an Email or Publish to Confluence - What should you do with your release notes?

Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...

136 views 1 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you