POST to 'Downloads' failing - Bad Request (400).

I'm trying to perform a POST using Invoke-WebRequest using a Powershell script. I'm getting a Bad Request (400) error which from my understanding means there is something wrong with the way I'm doing the POST. Here is my Powershell script:

#Create a credential variable for account$cred = Get-Credential$postParams = @{files='.\Hello.txt'}try {
    Invoke-WebRequest -Credential $cred -Uri https://api.bitbucket.org/2.0/repositories/myBitbucketUsername/myRepoName/downloads -ContentType "multipart/form-data" -Method POST -Body $postParams}catch {echo '### Inside catch ###'    $ErrorMessage = $_.Exception.Message     echo '## ErrorMessage ##' $ErrorMessage
    $FailedItem = $_.Exception.ItemName     echo '## FailedItem ##' $FailedItem 
    $result = $_.Exception.Response.GetResponseStream()     echo '## result2 ##' $result
    $reader = New-Object System.IO.StreamReader($result)     echo '## reader ##' $reader 
    $responseBody = $reader.ReadToEnd();     echo '## responseBody ##' $responseBody}pause

Here is the info I get from the catch block when executing the script:

### Inside catch ###
## ErrorMessage ##
The remote server returned an error: (400) Bad Request.
## FailedItem ##
## result2 ##


CanTimeout   : True
ReadTimeout  : -1
WriteTimeout : -1
CanRead      : True
CanSeek      : True
CanWrite     : True
Capacity     : 256
Length       : 26
Position     : 26

## reader ##
CurrentEncoding : System.Text.UTF8EncodingBaseStream      : System.Net.SyncMemoryStream
EndOfStream     : True

## responseBody ##    

I'm unsure of what I'm doing wrong. The file I am trying to POST (Hello.txt), is located on the Desktop which also contains the Powershell script. 

0 answers

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

22,146 views 26 11
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you