The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

NoSuchPathException in the bitbucket github api

Hari Prasanth
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!
February 1, 2022

Hi Team,

We are using Bitbucket github and I am using their API to update an file like below

https://docs.atlassian.com/bitbucket-server/rest/5.7.0/bitbucket-rest.html#idm45568365784624

In case of updating the README.md, it works as expected

curl -X PUT -u username:password -F content=@README.md -F 'message=Updated using file-edit REST API'
-F branch=master -F sourceCommitId=5636641a50b
http://example.com/rest/api/latest/projects/PROJECT_1/repos/repo_1/browse/test/README.md

Updating the file in github repo works as expected but when I try to create the new file path like below

curl -X PUT -u username:password -F content=@README.md -F 'message=Updated using file-edit REST API'
-F branch=master -F sourceCommitId=5636641a50b
http://example.com/rest/api/latest/projects/PROJECT_1/repos/repo_1/browse/test/newfile.md

it fails with the error : **NoSuchPathException**

{
"errors": [
{
"context": null,
"message": "test/newfile.md could not be edited because the file has been deleted on the 4186264533e065bd10ad2baf307f5687afcb445c branch.",
"exceptionName": "com.atlassian.bitbucket.content.NoSuchPathException"
}
]
}

As per the documentation, It says both the update and create should work as expected but only UPDATE is working and CREATING A NEW FILE fails

**branch: the branch on which the path should be modified or created**

Anyhelp on this is appreciated!

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
K_ Amritha
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 9, 2022

For people running into this issue, you need to remove the sourceCommitId parameter for new files. Seems like the sourceCommitId is needed only for existing files.

TAGS
AUG Leaders

Atlassian Community Events