Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

get last modified of each file using REST API in python

kims
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!
November 18, 2024

Hello all,

Im trying to make a list of all files with last modified date and this is my first time to use REST api. Therefore i am following the guide in https://docs.atlassian.com/bitbucket-server/rest/7.21.0/bitbucket-rest.html#idp278 

 

in the REST docs, it says that using "/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/last-modified" is the way to get last modified information of each files.

based on this guide, i create a simple python code like below

def getLastModified():

  url = "https://url/rest/api/1.0/projects/myprojectname/repos/thereponame/last-modified"

  auth=HTTPBasicAuth('myid', 'mypw')

  response = resquest.get(url, auth=auth)

if(response.status_code != 200):
print('API fail')
else:
pass #todo


if __name__ == '__main__':

getLastModified()

however when i run this python code, the response has error code 400 which indicates bad request.

other APIs, such as 'files' and 'participants', work well if i just replace text of 'last-modified' to 'files' or 'participants' according to the atlassian document.

e.g.) url = "https://url/rest/api/1.0/projects/myprojectname/repos/thereponame/files"

i have no idea why the only 'last-modified' does not work and return error code 400.

 

What i need is the last modified date of each file in the trunk to create reports of my code status.

 

If anyone possible, please give me a kind advice to me.

 

Kind regards,

Kim
  

1 answer

1 accepted

0 votes
Answer accepted
kims
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!
November 19, 2024

okay i found the right way to use the API by myself.

commit number should be provided in the url and the path, in case of checking specific folder, should be ended with '/'.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events