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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

Edited

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

Got the answer.

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

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events