Hi there,
Here's what I am trying to accomplish:
> I have a script on ServiceNow that comes up with the contents of a JSON file (doesn't actually create the file). We currently have a rather elaborate architecture to get this content inserted as a JSON file into a BitBucket repo.
> I am wondering if there is a REST API provided by BitBucket that would allow me to instead create a file with content-type as JSON and insert the contents generated by my script as an XML/JSON payload.
Thanks in advance for your help.
Hello Srikanth and welcome to the Community!
To upload files into Bitbucket will depend on the Bitbucket product you’re using. I will break down the answer for uploading by Cloud and Server. (This will also depend on the scripting language you’re using to compile your JSON file along with how you’re making your API calls).
For Bitbucket cloud I would suggest the following method;
For Bitbucket server I would suggest the following method;
Depending on with product you choose, you will need to have your file stored in a way that allows you to upload/PUT it into Bitbucket.
I hope this proves helpful for getting your JSON content into Bitbucket.
Regards,
Stephen Sifers
Hi Stephen,
Thank you for taking the time to answer my question, I am a bit confused as to how I would create the file.
The method we currently use allows us to provide the filename, extension and file content which is stored as a record on a ServiceNow table. This record is then pulled in by a ServiceNow application installed on our servers called the MID server which generates the file based on the aforementioned file attributes.
I am wondering if perhaps there is a way to instead call a BitBucket API with the JSON content as a payload thereby creating a new file in the repo for further consumption.
Please let me know if my question isn't clear and I'll provide more information.
Regards,
Srikanth
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Srikanth,
Thank you for providing additional information and clarification into what you want to do.
The only endpoint that I’m able to find to upload data into Bitbucket server via the REST API is /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/browse/{path:.*} which requires a path/file to be included. Perhaps within your script, you may convert the JSON payload into a filetype as a variable and then include that. This will all depend on the scripting language you use.
What it sounds like is that you want to commit code to Bitbucket server but use the REST API instead of Git commands to make your commit. An alternative would be to store your files in a git repository locally and script your git commits instead of using the REST API. This may not apply to how your integration is configured though.
I hope this provides helpful and gives some insight into how to upload a file and an alternative to using the REST API.
Regards,
Stephen Sifers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am trying to do something similar with Bitbucket Server but getting a 415.
Based on the documentation, if creating a file the source commit Id has to be left to null, which I am doing, and all the other data I am providing in the body as a json, including the file content and doing a put request to the file path on the repo.
I am using powershell. Unfortunately the documentation isn’t very good as it only gives an example using curl and the other languages don’t really have a good example.
also, if I wanted to get the sourceCommitId of a file, how would I do that? I don’t see an endpoint for it, just for getting the latest commit on the whole repo, as opposed to a file.
any help will be greatly appreciated.
Thnx
Rob
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.