How to get last modified or created date using rest api?

Hidayat Ullah February 10, 2023

Hi,

I want to get date for a file last modified or for created mean when the  file is created or when it's was last modified.

Is there any api I can used to fetch the date ?

 

Thanks

 

1 answer

1 vote
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 13, 2023

Hi @Hidayat Ullah,

You can use the following API endpoint to list all commits that modified a certain file:

If you use the parameter ?fields=%2Bvalues.commit.date in the URL you will also get the date of each commit, e.g.:

curl -u Bitbucket_Username:App_Password -X GET -H "Content-Type: application/json" https://api.bitbucket.org/2.0/repositories/{workspace-id}/{repo}/filehistory/master/{myFile.css}?fields=%2Bvalues.commit.date

The commit with the earliest date should be the one that created the file, while the one with the latest date should be the last modified for this branch.

Please note that the API URL needs a commit hash or a branch name and it looks for commits on a specific branch or reachable from the commit hash you provide. If you want to check the last modified date for different branches, you will need to run one API call per branch.

If you have any questions, please feel free to let me know.

Kind regards,
Theodora

jcraig May 3, 2023

Thanks, Theodora,

Is this curl statement for BitBucket Cloud? I'm using BitBucket Server and I'm not sure how to incorporate my server name into the curl statement. This doesn't work...

curl -u user:pass -X GET -H "Content-Type: application/json" https://host:7990/rest/api/2.0/repositories/vrc/vrc/filehistory/master/README.md?fields=%2Bvalues.commit.date

 I get the response:

curl: (35) schannel: next InitializeSecurityContext failed: SEC_E_INVALID_TOKEN (0x80090308) - The token supplied to the function is invalid

The Server REST API doesn't seem to have a "filehistory" command: REST Resources Provided By: Bitbucket Server - REST (atlassian.com)

Thanks for your help!

Joel

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 5, 2023

Hi Joel,

The info I shared is for Bitbucket Cloud only, Bitbucket Server has different APIs.

The following API endpoint for Bitbucket Server has the query parameter path:

You can use that to get all commits that modified a certain file, for example;

http://{baseurl}/rest/api/latest/projects/{projectKey}/repos/{repositorySlug}/commits?path=src/file.txt

Kind regards,
Theodora

Like Hamilton Carter likes this

Suggest an answer

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

Atlassian Community Events