How to fetch all repositories of any workspace in bitbucket using bitbucket APIs

Hey everyone 😄 recently I completed a team project regarding set up some CI/CD with Rest API and because it should have CI/CD so we use Jenkins but in here I am going to demonstrate that "How to fetch all repositories of any workspace in bitbucket ". So here, we use bash script and bitbucket rest API 

But first, we need to understand curl command.

Well according to GfG:- "curl is a command-line tool to transfer data to or from a server, using any of the supported protocols (HTTP, FTP, IMAP, POP3, SCP, SFTP, SMTP, TFTP, TELNET, LDAP or FILE). This tool is preferred for automation since it is designed to work without user interaction. curl can transfer multiple files at once."

So hey we know, we need curl for sending/receiving request and response from bitbucket server.

The other thing we need is bitbucket APIs which can found in here Bitbucket API. In the website, there are lots of APIs available but we need only this one {workspace}

So we have both things now let's jump to the coding part 

In the above code, I use the following URL 


But as you can see I added some extra fields in the URL which are "pagelen", "page"  and "fields".

  1. pagelen:- pagelen is basically a length of page or how much data we need to have in a single response. In here we get 100 repository's data i.e names, links and branches in a single response by adding pagelen=100.
  2. page:-  page is basically used to specify the page of results to return. In here we use count variable so we can fetch all pages.
  3. fields:- With fields you can determine how much more data is available within the API or you can inspect/select particular data to receive in response. In here we select only following fields in response fields=next,values.links.branches.href,values.full_name
So now we know what actually this URL doing.

Note:- Be sure you created data.json file because the resultant data will store in there.

In the end, we get JSON data of all repositories.

Hope you enjoyed my blog post.😎


Popular posts from this blog

How to pass parameters in webhook?

Access and modify all the resources of our Wiki.js using WikiJS API

Fahrenheit to Celsius