Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to add a brand new file to bitbucket using server api

Kaushal Krishna January 5, 2023

Not able to add new file using bitbucket server api.

Also please help me in repairing my code. 

auth is repository access token

from variables import base_url,repo,file,username,auth

import requests
import json

url = f"http://{base_url}/rest/api/latest/projects/~{username}/repos/{repo}/browse/{file}"

contents=None
with open(file,"r") as f:
contents=f.read()

payload={
"branch": "master",
"content": contents,
"message": "Holla",
"sourceCommitId": None
}


headers = {
"Accept": "application/json",
"Authorization": f"Bearer {auth}",
"Content-Type": "multipart/form-data"
}

response = requests.request(
"PUT",
url,
headers=headers,
json=payload
)


print(response)

Can someone please help ???????????

1 answer

1 accepted

1 vote
Answer accepted
Kaushal Krishna January 7, 2023

Got the answer.

Sumeet Rawal February 28, 2023

Hi @Kaushal Krishna , I'm using the same api to add a file to repo and getting the following error response:
409


{
"errors": [
  {
"context": null,
"message": "Support for editing files has been disabled.",
"exceptionName": "com.atlassian.stash.internal.rest.content.ContentResource.FileEditorDisabledException"
  }
    ]

}


 

Did u face the same issue? If yes .. can u pls help me understand and fix it

venkatesh vp September 5, 2023

I am not clear with what is accepted. Pls do provide the details. instead of the python code  can we use a cul command to add file in the repo.

rajeshkumar.kumar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 4, 2024

Hi @Kaushal Krishna ,

what is the answer ? can you please share it? what is the final api endpoint which you have used?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events