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
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

439 views 6 9
Read article

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