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

How to use bitbucket repository access token to edit a file with bitbucket server rest api .

Kaushal Krishna January 6, 2023

I need to know if we could use the repository access token to perform edit/push a file with bitbucket server rest api.

Because it is showing the "When performing an edit, the author must have an e-mail address" error .

If someone can show me how to add the email address (without adding personal access token) to the payload then I would be grateful .

Using personal access token will be sort of risky to use .

auth=repository access token

The code :

import json
from variables import *
import requests
import logging

# logger=logging.getLogger()
# logging.basicConfig(filename = 'myfile1.log', level=logging.DEBUG,
# format='%(filename)s:%(lineno)s %(levelname)s:%(message)s')


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

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

payload={
"content": contents,
"message": "Holla",
"branch": "master",
"sourceCommitId": "016cf822394",
}
data={
"author":{
"name":"example",
"emailAddress":"ex@example.com"
}
}

headers = {
"Accept": "application/json",
"Authorization": f"Bearer {auth}"
}

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

)


print(response)
print(response.content)

1 answer

0 votes
Kaushal Krishna January 8, 2023

Can somebody help me ?

Mario Arturo Naranjo Garcia
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!
May 24, 2023

Currently i have the same issue, could you solve that?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events