Hello Atlassian Team,
I am currently using the Bitbucket Cloud REST API to delete a file from a repository by creating a commit. The API, I am using is the /src endpoint, as documented.
API being used:
curl -X POST \
'https://api.bitbucket.org/2.0/repositories/test_org18/bdtestrepo/src' \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
-F 'branch=test' \
-F 'message=Delete test.txt' \
-F 'testing.txt=' This API successfully creates a commit and clears the content of the file. However, the file name still appears in the repository tree (as a zero-byte / empty file), instead of being removed entirely from the branch.
I would like to clarify the following:
/src endpoint the only supported API for file deletion with a commit in Bitbucket Cloud?I have reviewed the Bitbucket REST API documentation but could not find any alternative API or option to delete the file instead of erasing of content.
Any clarification on this behavior would be very helpful.
Thank you.
May I ask why you are trying to do this with the REST API and not with a git?
To answer your question:
According to the endpoint's documentation you can delete files by using the files parameter.
The example they provide is:
curl https://api.bitbucket.org/2.0/repositories/username/slug/src \ -F files=/file/to/delete/1.txt
What you are doing with -F 'testing.txt=' is setting the file contents of testing.txt to empty, you're not deleting it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.