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

**URL:** <https://forums.powershell.org/t/how-to-upload-local-file-to-git-bitbucket-using-the-invoke-restmethod/14750>\
**Category:** PowerShell Help\
**Created:** [August 3, 2020, 3:42am UTC](https://forums.powershell.org/t/how-to-upload-local-file-to-git-bitbucket-using-the-invoke-restmethod/14750 "2020-08-03T03:42:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![veljko](https://avatars.discourse-cdn.com/v4/letter/v/dbc845/32.png) [@veljko](https://forums.powershell.org/u/veljko)\
**Post date:** [August 3, 2020, 3:42am UTC](https://forums.powershell.org/t/how-to-upload-local-file-to-git-bitbucket-using-the-invoke-restmethod/14750/1 "2020-08-03T03:42:01Z")

</div>

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???

&nbsp;

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!!!

```

```

```

```

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [August 3, 2020, 6:25am UTC](https://forums.powershell.org/t/how-to-upload-local-file-to-git-bitbucket-using-the-invoke-restmethod/14750/2 "2020-08-03T06:25:03Z")

</div>

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

API reference: [Latest updates](https://developer.atlassian.com/bitbucket/api/2/reference/?utm_source=%2Fbitbucket%2Fapi%2F2%2Freference&amp;utm_medium=302)

---

<div class="post-metadata">

**Author:** ![veljko](https://avatars.discourse-cdn.com/v4/letter/v/dbc845/32.png) [@veljko](https://forums.powershell.org/u/veljko)\
**Post date:** [August 4, 2020, 4:02am UTC](https://forums.powershell.org/t/how-to-upload-local-file-to-git-bitbucket-using-the-invoke-restmethod/14750/3 "2020-08-04T04:02:22Z")

</div>

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

&nbsp;

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [August 5, 2020, 10:52am UTC](https://forums.powershell.org/t/how-to-upload-local-file-to-git-bitbucket-using-the-invoke-restmethod/14750/4 "2020-08-05T10:52:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![veljko](https://avatars.discourse-cdn.com/v4/letter/v/dbc845/32.png) [@veljko](https://forums.powershell.org/u/veljko)\
**Post date:** [August 5, 2020, 11:42pm UTC](https://forums.powershell.org/t/how-to-upload-local-file-to-git-bitbucket-using-the-invoke-restmethod/14750/5 "2020-08-05T23:42:53Z")

</div>

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

Thanks

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/how-to-upload-local-file-to-git-bitbucket-using-the-invoke-restmethod/14750/6 "2024-05-16T20:29:05Z")

</div>


