Download an Raw file from BITBUCKET Project…
- Fri, Jun 22 2018 at 2:32 am #605268
Guys i am trying to hit an wall ( In powershell i am Trying to download an file( say simple text file) from bitbucket private repository however i am able to download the file , though it is coming as an HTML one not as the raw one).
can someone please help me or point it out where i am lacking in the command.
Invoke-WebRequest -Credential XYZ -Uri https://api.bitbucket.org/1.0/repositories/company/project/raw/HEAD/some/special/file.txt-OutFile .file.txt
file.txt is downloaded as HTML not as the raw one.
- Fri, Jun 22 2018 at 3:36 am #605667
My guess is that something went wrong with the authentication. What is “XYZ”? How did you read the credentials?
- Fri, Jun 22 2018 at 4:06 am #605673
Invoke-WebRequest -Credential manish.garg -Uri https://api.bitbucket.org/1.0/repositories/company/project/raw/HEAD/some/special/file.txt-OutFile .file.txt
Check here!!! XYZ i just put any random user name….it is not authentication problem.
Michael – how do we download an single file( in the raw form) from bitbucket project(git repo)
- Fri, Jun 22 2018 at 4:11 am #605677
When I open the URL https://api.bitbucket.org/1.0/repositories/company/project/raw/HEAD/some/special/file.txt I receive this error message:
That link has no power here.
I suppose this means that you are unable to access file.txt without authentication. You probably just need to authenticate properly.
- Fri, Jun 22 2018 at 4:19 am #605682
this is also an random url….exact url i support you wouldn’t be able to access…since it is an private repo….
that’s why mentioned any pseudo url…here is the deal…think about it…
Invoke-WebRequest -Credential <<manish.garg>> -Uri <<HERE I’ll GIVE BITBUCKET REPO URL>> -OutFile <<FILENAME>>
HERE FILE IS DOWNLOADED BUT AS HTML NOT AS THE RAW ONE…
CAN YOU PIN POINT IN ABOVE COMMAND WHAT I AM DOING WRONG WHICH IS NOT LETTING THE DOWNLOAD PROPERLY.
- Fri, Jun 22 2018 at 4:37 am #605686
Your commands looks okay. If it doesn’t work, either the URL or the credentials are wrong.
Did you read the credentials like this:
$Credentials = Get-Credential Invoke-WebRequest -Uri "https://www.contoso.com" -OutFile "C:\path\file" -Credential $Credentials
You can also have a closer look at the HTML file you receive. This will give you clues what went wrong.
- Fri, Jun 22 2018 at 7:30 am #605692Bryce McDonaldParticipantMember Points: 209Rank: 2
As an FYI, version 1 of the BitBucket API is being deprecated at the end of this month. Has your org already switched to using version 2 of the API? It could be because of that. If I remember correctly, version 2 needs an OAUTH token for the $credentials parameter, rather than something that Get-Credential would return.
- Fri, Jun 22 2018 at 5:42 pm #605724ChrisParticipantMember Points: 46Rank: 1
There are a few things that could be going on, you’ll need to do a bit more digging to figure it out. I’ll start by suggesting a tool (Postman) and giving a bit of context into what’s probably going on.
This is what an http conversation actually looks like. Red is what we send, blue is what we get back.
Here’s a practical example in postman (calling out to google.com)
Notice there’s 2 places we can send parameters, in the URI and in the Headers. One of the standard headers is Content-Type which indicates the format the web server is trying to send back to you.
Try installing Postman, putting in your URI and playing around values you send in the URI and Headers, there’s probably a way to ask for it to send a text/plain instead of text/html file. Once you know what the URI and Headers need to be you should be able to translate your request into powershell code using the -URI and -Headers parameters
- Fri, Jun 22 2018 at 5:49 pm #605728ChrisParticipantMember Points: 46Rank: 1
In essence what I’m saying is the problem isn’t so much with your powershell code as with your actual request to BitBucket. It thinks you’re a web browser, there’s probably some parameter they’ll accept (either in the headers, as a URI parameter after the ? or using a particular URI path) to tell them you just want to download the file, not view it.
You could also try changing from this to that
- You must be logged in to reply to this topic.