I'm trying to POST a file to the 'Downloads' section of a Bitbucket repository. I'm following this page from Bitbucket's documentation. I'm trying to do this by writing a Powershell script. I've managed to get the GET method to work with:
#Invoke-RestMethod -Credential $cred -Uri https://api.bitbucket.org/2.0/repositories/myBitbucketUsername/myBitbucketRepoName/downloads?access_token=9EtOz9JDeWGwxTLKx3ya2oPE8g652GoLN0cMmtD0Ncvkf2OXoio0bcXwSigNE9AXTT2aj6qmbS5XHae7rIc%3D"&"scopes=pipeline%3Avariable+webhook+snippet%3Awrite+wiki+issue%3Awrite+pullrequest%3Awrite+repository%3Adelete+repository%3Aadmin+project%3Awrite+team%3Awrite+account%3Awrite"&"expires_in=3600 -OutFile .\file.txt
In order to get that GET to work I had to add the access token which I made through Bitbucket (hence all the text for the access token portion of the Uri).
I'm not sure how to perform the POST. I've tried several things including something similar to the documentation:
curl -s -u myBitbucketUsername -X POST https://api.bitbucket.org/2.0/repositories/myBitbucketUsername/myBitbucketRepoName/downloads -F files=@Hello.txt
The error I get inside Powershell when running this command is:
Invoke-WebRequest : Parameter cannot be processed because the parameter name 'u' is ambiguous. Possible matches include:
-UseBasicParsing -Uri -UseDefaultCredentials -UserAgent.
At C:\Users\user\Desktop\ScriptTest.ps1:21 char:9
+ curl -s -u myBitbucketUsername-X POST https://api.bitbucket.org/2.0/reposit ...
+ ~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameter,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
I've also tried with the access token added to the URL (similar to how I did the GET).
The file I am trying to POST is 'Hello.txt' which is on my Desktop - the same location as my Powershell script.
Any ideas?
EDIT:
I've followed briantist's advice and switched to using credentials instead. Now, I get a 'Bad Request (400)
' error. Here is my code:
$postParams = @{files='.\Hello.txt'}
Invoke-WebRequest -Credential $cred -Uri https://api.bitbucket.org/2.0/repositories/myBitbucketUsername/myRepoName/downloads -ContentType "multipart/form-data" -Method POST -Body $postParams