How to upload local File to Git (Bitbucket) using the Invoke-RestMethod?

Welcome Forums General PowerShell Q&A How to upload local File to Git (Bitbucket) using the Invoke-RestMethod?

Viewing 4 reply threads
  • Author
    Posts
    • #246759
      Participant
      Topics: 10
      Replies: 9
      Points: 139
      Rank: Participant

      Using the Invoke-RestMethod I can successfully download files from BitBucket (GIT):

      [/crayon]

      Can you please advise me what will be the scenario and Invoke-RestMethod if I want to upload local test2.json file to the location in the same directory  ..../repos/select/browse/test_scripts/ (preferably on master branch on Git)? I am not sure also if I need to create also in the same time new subfolder on Bitbucket repository how I can do it?

      [/crayon]

      Please tell me how the  Invoke-RestMethod should look like? I know I need to use the  -Method Post but do not know how to reference my local file that needs to be uploaded???

       

      I tried something like this, to put local file into some repos path (but it doesn’t work):

      $API_KEY=” <span class="str">ZTEyNDU2</span>
      <span class="pln">$uri</span><span class="pun">=</span><span class="str">"https://bitbucket.dev/projects/TEST/repos/select/browse/test_scripts/</span>
      $jsonFile=Get-Content -Raw -Pat C:\Users\Downloads\test2.json
      Invoke-RestMethod -Uri $uri -Headers @{Authorization=”$(“Basic {0}” -f $API_KEY)”} -Method ‘POST’ -Body $jsonFile -ContentType ‘application/json’

      Thank you in advance!!!!

      [/crayon] [/crayon]
    • #246810
      Senior Moderator
      Topics: 9
      Replies: 1309
      Points: 4,781
      Helping Hand
      Rank: Community Hero

      You have to find the right API to use here, then using Invoke-RestMethod will be very simple.

      API reference: https://developer.atlassian.com/bitbucket/api/2/reference/?utm_source=%2Fbitbucket%2Fapi%2F2%2Freference&utm_medium=302

    • #246984
      Participant
      Topics: 10
      Replies: 9
      Points: 139
      Rank: Participant

      Hi,

      thank but do you know maybe how would you push the files to regular git repository? Can you at least provide me with those examples?

      Can you please give me an example how the branch is being created/new folders on repository and so on…?

      Also I am using bit bucket API version 1.0 and not 2.0.

      I tried like this to push:

      Invoke-RestMethod -Uri $uri -Headers @{Authorization=”$(“Basic {0}” -f $API_KEY)”} -Method ‘POST’ -Body $jsonFile -ContentType ‘application/json’

      but it mentioned me that POST method is not allowed. But I have doubts if this is really not allowed since with “git push” I can upload the files to that BitBucket.

      Also, I will be thankful if someone else can explain me how I can upload file through the API to the Bitbucket (Git)?

      Thank you in advance,

      Veljko

       

    • #247312
      Senior Moderator
      Topics: 9
      Replies: 1309
      Points: 4,781
      Helping Hand
      Rank: Community Hero

      just curious to know, why do you go with REST APIs when git commands can do all these ?

    • #247462
      Participant
      Topics: 10
      Replies: 9
      Points: 139
      Rank: Participant

      Because this must be done from external system, through the integration – to send specific file through the REST API.

      Thanks

Viewing 4 reply threads
  • You must be logged in to reply to this topic.