The Bitbucket Cloud API supports adding a file:
https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/src?_ga=2.166720184.785263539.1561033805-1461619870.1560541353#post
Is this functionality available for the Bitbucket Server API?
Hello Daavid and welcome to the Community!
From reviewing your request for the cloud API you want to be mirrored over in server there is an API which you can use on server. The similar REST API endpoint you’re wanting to use is as follows; /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/browse/{path:.*}.
This endpoint will allow for the following;
The file can be updated or created on a new branch. In this case, the sourceBranch parameter should be provided to identify the starting point for the new branch and the branch parameter identifies the branch to create the new commit on.
I hope this information proves helpful and you’re able to upload/add files to Bitbucket server without issue.
Regards,Stephen Sifers
Thank you! This is what I needed.
@Stephen Sifers I have an issue when I send request that time I receive 415 unsupported media type responses. Content-type(application/json). Basically, I have to create the text file and inside the file send a text.
```https://local.com/rest/api/1.0/projects/XXX/repos/XXXX/browse/test.txt ```
Hello Dinkar,
This post is a bit old so the links are referencing an older version, please see /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/browse/{path:.*}
The example curl call there is as follows:
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/README.md
@Stephen Sifers i have issue, when i try to use the API you have mentioned above is not working. instead of updating the file content is reading the file. i have added sample curl which i have tried,
curl --location --request PUT 'http://example.com/rest/api/1.0/projects/PROJECT_1/repos/repo_1/browse/test.json' \--header 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \--form 'content=test changes' \--form 'message=Updated using file-edit REST API' \--form 'branch=development'
Please help me to fix this issue
Hello @arun
The answer above is almost 3 years old, and with Bitbucket Server 7.21 being available, it may no longer apply (As the above reference links to 6.4).
With this said, in Bitbucket Server you could attempt the following endpoint and example:
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/browse/{path:.*}
This API can also be invoked via a user-centric URL when addressing repositories in personal projects.Update the content of path, on the given repository and branch.
path
repository
branch
This resource accepts PUT multipart form data, containing the file in a form-field named content.
content
An example curl request to update 'README.md' would be:
sourceBranch
@Stephen Sifers yes i have referred the same doc and tried the same as u have mentioned. You can check the sample curl comment in the above comment.But still instead of updating the content in the file it’s reading the content from the file what we passed in the path. Is there anything I’m doing wrong here or what could be the issue.
thanks ,
Arun s
The only issue I may see is your use of the --location since it seems you're using a proxy server. It may not be possible for your to test without the proxy since it's in place for a reason, but do see if you can test without your proxy.
What I see with -L or --location is the following:
When curl follows a redirect and if the request is a POST, it will send the following request with a GET if the HTTP response was 301, 302, or 303. If the response code was any other 3xx code, curl will re-send the following request using the same unmodified method. You can tell curl to not change POST requests to GET after a 30x response by using the dedicated options for that: --post301, --post302 and --post303. The method set with --request overrides the method curl would otherwise select to use.
When curl follows a redirect and if the request is a POST, it will send the following request with a GET if the HTTP response was 301, 302, or 303. If the response code was any other 3xx code, curl will re-send the following request using the same unmodified method.
You can tell curl to not change POST requests to GET after a 30x response by using the dedicated options for that: --post301, --post302 and --post303.
The method set with --request overrides the method curl would otherwise select to use.
Source: https://curl.se/docs/manpage.html
It looks like you're new here. Sign in or register to get started.