Missed Team ’24? Catch up on announcements here.

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

Return commit hash after creating a commit using API

Jonathan Li April 5, 2023

The Create a commit by uploading a file endpoint doesn't return anything. I need the commit hash that it has created. Is there a workaround for this?

2 answers

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

Hi @Jonathan Li!

With curl, it is possible to add the -v option, as follows:

curl -u BitbucketUsername:AppPassword -v https://api.bitbucket.org/2.0/repositories/workspace-id/repo/src \
-F myFile.txt=@myFile.txt

When the -v option is added, the output will return, among other things, a line that looks like this:

< location: https://api.bitbucket.org/2.0/repositories/workspace-id/repo/commit/361fbb45757afc4056a400730bd6cf6fe3e77c07

The last part is the commit hash of the commit created by the API call.

Kind regards,
Theodora

0 votes
Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 6, 2023

If it doesn't return it, maybe you could get the refs from the repo right after you created the commit. Because you know to which branch you created the commit, you need the hash of the head of that branch.

(You could even get the branch itself from the REST API, but as far as I saw it won't return the hash either?!)

Anyway, it should give you an idea.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events