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

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

$API_KEY="ZTEyNDU2"
$uri="https://bitbucket.dev/projects/TEST/repos/select/browse/test_scripts/test1.json?raw"
Invoke-RestMethod -Headers @{Authorization="$("Basic {0}" -f $API_KEY)"} -Uri $uri  -OutFile "test1.json"

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?

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=“ZTEyNDU2
$uri=https://bitbucket.dev/projects/TEST/repos/select/browse/test_scripts/
$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!!!



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

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

 

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

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

Thanks