Download an Raw file from BITBUCKET Project…

Viewing 7 reply threads
  • Author
    Posts
    • #605268
      Manish
      Participant
      Member Points: 106
      Rank: 2

      Hey there?
      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.

    • #605667
      Michael Pietroforte
      Keymaster
      Member Points: 40,154
      Author of the year 2018
      Rank: 4

      My guess is that something went wrong with the authentication. What is “XYZ”? How did you read the credentials?

    • #605673
      Manish
      Participant
      Member Points: 106
      Rank: 2

      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)

    • #605677
      Michael Pietroforte
      Keymaster
      Member Points: 40,154
      Author of the year 2018
      Rank: 4

      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.

    • #605682
      Manish
      Participant
      Member Points: 106
      Rank: 2

      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.

    • #605686
      Michael Pietroforte
      Keymaster
      Member Points: 40,154
      Author of the year 2018
      Rank: 4

      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.

    • #605692
      Bryce McDonald
      Participant
      Member Points: 209
      Rank: 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.

    • #605724
      Chris
      Participant
      Member Points: 47
      Rank: 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.
      wireshark google
      https://ibb.co/bEfn9o

      Here’s a practical example in postman (calling out to google.com)
      postman google
      https://ibb.co/isjavT

      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

Viewing 7 reply threads
  • You must be logged in to reply to this topic.
© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account