Is there any APIs to pull all the repositories from a particular Organisation
Asked by Amiya Kumar Sahoo:

Is there any APIs to pull all the repositories from a particular Organisation?( using one param like workspaceID, projectkey etc )  

1.{{const

{ data, headers } = await bitbucket.teams.listRepositories({ workspace, page, pagelen, q, sort, fields })}}  

<br />

2. {{const { data, headers }

= await bitbucket.teams.listRepositoriesForUser(

{ workspace, page, pagelen, q, sort, fields }

)}}  

3.

{{const

{ data, headers } = await bitbucket.users.listRepositories({ workspace, page, pagelen, q, sort, fields })}}  

4.{{const { data, headers }

= await bitbucket.users.listRepositoriesForTeam(

{ workspace, page, pagelen, q, sort, fields }

)

<br />

I tried these 4 Apis in postman, but these all are deprecated   


Answers:
author: Guilherme Franchi
body: Hello Amiya,

So, let me try to help you with your issue.

You are totally right, all of those API's that you have listed are now deprecated. Actually, if you see the API description, in our Atlassian Developer's portal, you should see the following information: **"This endpoint has been removed. You should use the [workspace](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-workspaces/#api-workspaces-get) endpoint instead. For more information, see [this post](https://developer.atlassian.com/cloud/bitbucket/bitbucket-api-teams-deprecation/)."**

Also, as you may know, Bitbucket use *Teams* similar to GitHub's organizations. But, teams resource has been deprecated, and the workspaces endpoint should be used instead.

Try to take a look at the documentation provided above. And, as a plus information, I would recommend you to use/try the "Atlassian REST API Browser" from the marketplace ([Atlassian REST Api Browser](https://marketplace.atlassian.com/apps/1211542/atlassian-rest-api-browser?tab=overview&hosting=server)) as you can see all the APIs and also make requests directly from that browser to test your results.

Hope that it helps!! And that you have a great week ahead!  

Please, do not hesitate on contacting us again in case you need any additional information!  

Kindly Regards,

**Guilherme Franchi**

*Atlassian Support Engineer*

comments: author: Amiya Kumar Sahoo
body: Hi [Guilherme Franchi](https://community.atlassian.com/t5/user/viewprofilepage/user-id/4694542),  

I have also looked into the workspace endpoint but could not find any api that can be used to pull all the repos.   
All the Apis that are mentioned to do so are deprecated.  

If you find any API that can be used to pull all the repos of a team/organisation/project kindly provide me any that.  

<br />

Thanks for the response  
Amiya


author: Guilherme Franchi
body: Hi [@Amiya Kumar Sahoo](/t5/user/viewprofilepage/user-id/4279037)

Thanks for replying me back.

Actually, there is not a single API capable of doing so. What you will need to do is to work with a series of APIs, based on the application that you working with, to be able/capable of doing that.

I will use an example here, where we can set an OAuth2 authentication, using curl, and getting all the repository from my workspace. (For mor information about **OAuth2** you can check the following page: [OAuth2](https://developer.atlassian.com/cloud/bitbucket/oauth-2/)).

The first thing that you need to do is to create a consumer:

### Creating a consumer {#toc-hId-1314461419}

OAuth needs a key and secret, together these are know as an OAuth consumer. You can create a consumer on any existing workspace. To create a consumer, do the following:

1. From your profile avatar in the bottom left, click on the workspace in the **Recent workspaces** list or click **All workspaces**to open an entire list from which to choose.

2. Click **Settings**on the left sidebar to open the Workspace settings.

3. Click **OAuth consumers** under **Apps and features**on the left navigation.

4. Click the **Add consumer** button.

   The system requests the following information:

   Field

   Description

   **Name** The display name for your consumer. This must be unique within your account. This is required.**Description** An optional description of what your consumer does.**Callback URL**

   Required for OAuth 2.0 consumers.

   When making requests you can include a call back URL in the request:
   * If you do include the URL in a request it must be appended to the same URL configured in the consumer. So if your consumer callback URL is example.com/add-on the URL in your request must be something similar to example.com/add-on/function.

   * If you don't include the URL in the request we redirect to the callback URL in the consumer.

   **URL**An optional URL where the curious can go to learn more about your cool application.
5. Click **Save** .   
   The system generates a key and a secret for you.

6. Toggle the consumer name to see the generated **Key** and **Secret** value for your consumer.

Once you have that setup, you can request a token, using that **Key** and **Secret** value from your consumer:

```

# Making a request of an OAuth2 token, using a private client_credentials
curl -X POST https://bitbucket.org/site/oauth2/access_token -d grant_type=client_credentials -u "CONSUMER_KEY:CONSUMER_SECRET"

```

The above POST curl call will return you with access_token that you will need to save to be able to make the next request.

Now, what I want to do is to get all the names of the repositories that I have in my name, based on my workspace:

```
# Show all the full name repositories that I have under my name,
# and format it out using jq
curl --request GET \
--url 'https://api.bitbucket.org/2.0/repositories/MY_WORKSPACE_USERID' \
--header 'Authorization: Bearer USE_THE_TOKEN_PROVIDED' \
--header 'Accept: application/json' | jq -r '.values[] | .full_name'

```

And the above GET request will return me all the names/repositories that I have under my name/workspace:

```
#Results:
MY_WORKSPACE_USERID/bitbucketstationlocations
MY_WORKSPACE_USERID/icecreamcontroller
MY_WORKSPACE_USERID/jetturbineavionics

```

With the above results, you can create a script or even an application to read it and make the pull/clone that you are looking for.

You can also check the following pages:

* [REST APIs - Repositories](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-repositories/)
* [REST APIs - Authentication Methods](https://developer.atlassian.com/cloud/bitbucket/rest/intro/#authentication)

Hope that it helps!

Regards,

Guilherme Franchi


Tags: bitbucket-cloud

cloud