Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

rest api to retrieve content of file

I am trying to migrate code that we wrote against gitlab to stash (3.1), one of these is a rest request to get the content as a file.


 This return the content as a set of lines: 

  "lines": [
      "text": "{"
      "text": "  \"name\": \"my-project\","
  "start": 0,
  "size": 3,
  "isLastPage": false

Is there a way to return the raw contents(text, base64) of the file instead of having text-text lines?

Also i can't tell from the rest api how to create or update just a file. 

2 answers

1 vote
Jeff Thomas Atlassian Team Dec 15, 2015

You may not be able to get the raw contents of the file from the REST API, but it's available if you tack on ?raw to the full URL of the file. For example, hitting https://{my-host}/projects/CLOUD/repos/myrepo/browse/package.json?raw should return the raw contents of that file.

Thanks!  Spent a lot of time trying to use the REST API to get the raw file, until I read this post.

Hi @Sudeep Yadav   the above is downloading package.json. It isnt fetching the content of package.json

@Shikha Priyedarshi - Can you share the details?

Hi Yes. In a groovy script I am trying to get the rawFile package.json in a variable like below:

``` def bitbucketResponse = "https://bitbucket_url/rest/api/1.0/projects/{projects}/repos/{repos}/raw/{path}/package.json".toURL().getText(requestProperties: [Accept: 'application/json', Authorization: \"Basic \${auth}\"])```


so when I tried only "https://bitbucket_url/rest/api/1.0/projects/{projects}/repos/{repos}/raw/{path}/package.json" in web browser it downloaded the package.json.

I saw one of your answers which includes the below url :



what is version here ?

@Shikha Priyedarshi - Oh you are trying it from browser.

Yes, that is expected behavior. Try to make this call using the Postman tool or through your groovy script and in that response you should get the correct value.

Note: You will have to use the respective authorization that you use. 

Yes am using this one from groovy : def xyz = https://bitbucket_url/rest/api/1.0/projects/{projects}/repos/{repos}/raw/{path}/package.json".toURL().getText(requestProperties: [Accept: 'application/json', Authorization: \"Basic \${auth}\"])

but it is not returning anything, the same command is getting stored in the  variable  to .

@Shikha Priyedarshi - I don't think this is how you make a call to a url, you are just assigning a value to a variable that is why it doesn't return anything.

Look up how to make call to endpoints in groovy and you will know what to do.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,227 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you