branch-restrictions Resource

Overview

This resource manages the branch restrictions on a repository. This resource has the following fields:

Field Description
pagelen An integer representing how many items to return per page. The default value is 10 and the maximum is 50. The caller can specify this value.
next The URL of the next page in the series. Only returned when there is a next page.
values An array of restriction data.
page An integer representing the current page.
previous The URL of the previous page in the series. Only returned when there is a previous page.
size The total number of items.

 The values array takes the following:

Field Description
groups An array of groups profiles corresponding to a set of groups. This field is always empty for delete and force restrictions.
id The URL of the next page in the series. Only returned when there is a next page.
kind

Type of restriction. This can be one of:

  • push
  • delete
  • force 
links An array of links for making REST calls to this resource.
pattern A repository pattern to match. This is only applied when kind is push. Accepts wildcards.
users An array of user profiles corresponding to a set of users. This field is always empty for delete and force restrictions.

When creating POST or PUT calls, the easiest way to pass data is as a JSON structure: 

To pass this to a curl call, create a file called body.json and pass it with the --data flag to curl:

curl -v --request POST --user username https://bitbucket.org/api/2.0/repositories/{usersname}/{repo-slug}/branch-restrictions  --header 'Content-Type: application/json; charset=utf-8' --data @json.data

GET the branch-restrictions

Gets the information associated with a repository's branch restrictions.  This call takes the following parameters:

Parameter Required Description
accountname Yes The account owner.
repo Yes The repository name.

GET https://bitbucket.org/api/2.0/repositories/{username}/{repo-slug}/branch-restrictions
  Click to expand and view a response...

POST the branch-restrictions

Creates restrictions for the specified repository. You should specify a Content-Header with this call.  This call takes the following parameters:

Parameter Required Description
accountname Yes The account owner.
repo Yes The repository name.
groups No One or more groups. This field is always empty for delete and force restrictions.
kind Yes

Type of restriction. This can be one of:

  • push
  • delete
  • force 
pattern No A repository pattern to match. This is only required when kind is [. Accepts wildcards.
users No An array of user profiles corresponding to a set of users. This field is always empty for delete and force restrictions.
POST https://bitbucket.org/api/2.0/repositories/{username}/{repo-slug}/branch-restrictions --header 'Content-Type: application/json; charset=utf-8' --data @json.data
Example curl comand
Example: body of call to add user branch restriction  Expand source
Response from add user branch restriction call  Expand source
Example: body of call to add group branch restriction  Expand source
Response from add group branch restriction call  Expand source

GET a specific restriction

Gets the information associated with specific restriction.  This call takes the following parameters:

Parameter Required Description
accountname Yes The account owner.
repo Yes The repository name.
id Yes The restriction's identifier.
GET https://bitbucket.org/api/2.0/repositories/{username}/{repo-slug}/branch-restrictions/{id}
  Click to expand and view a response...

PUT a branch restriction update

Updates a specific branch restriction. You cannot change the kind value with this call.  This call takes the following parameters:

Parameter Required Description
accountname Yes The account owner.
repo Yes The repository name.
groups No One or more groups. This field is always empty for delete and force restrictions.
id Yes The restriction identifier.
pattern No A repository pattern to match. This is only required when kind is push. Accepts wildcards.
users No An array of user profiles corresponding to a set of users. This field is always empty for delete and force restrictions.
PUT https://bitbucket.org/api/2.0/repositories/{username}/{repo-slug}/branch-restrictions/{id}
  Click to expand and view a response...

DELETE the branch restriction

Deletes the specified restriction.  This call takes the following parameters:

Parameter Required Description
accountname Yes The account owner.
repo Yes The repository name.
id Yes The restriction identifier.
DELETE https://bitbucket.org/api/2.0/repositories/{username}/{repo-slug}/branch-restrictions/{id}

Was this helpful?

Thanks for your feedback!

5 Archived comments

  1. User avatar

    Bogdan Taranu

    I think POST the branch-restrictions requires more information regarding the parameters.

    24 Apr 2014
    1. User avatar

      Bogdan Taranu

      Also, any example for POST the branch restrictions for push?

      24 Apr 2014
      1. User avatar

        Dan Stevens [Atlassian]

        Good day,

        I'm going to look into that and hopefully will have a better answer / response tomorrow. 

        Thanks for commenting.

        25 Apr 2014
      1. User avatar

        Dan Stevens [Atlassian]

        Bogdan, just to update you. I am working on updates to the documetation for this resource.

        Thank you for putting my eyes back on it. (smile)

        25 Apr 2014
    1. User avatar

      Dan Stevens [Atlassian]

      Good day Bogdan Taranu I've updated the post portion of this API please let me know if this helps.

      07 May 2014
Powered by Confluence and Scroll Viewport