branch-restrictions Resource

robotsnoindex
robotsnoindex

 

Overview

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

FieldDescription
pagelenAn 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.
nextThe URL of the next page in the series. Only returned when there is a next page.
valuesAn array of restriction data.
pageAn integer representing the current page.
previousThe URL of the previous page in the series. Only returned when there is a previous page.
sizeThe total number of items.

 The values array takes the following:

FieldDescription
groupsAn array of groups profiles corresponding to a set of groups. This field is always empty for delete and force restrictions.
idThe 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 
linksAn array of links for making REST calls to this resource.
patternA 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: 

{
    "kind": "TYPE",
    "pattern": "PATTERN",
    "groups": [{"owner": {"username": "USERNAME"}, "slug": "GROUPNAME"},{"owner": {...}...}], 
    "users": [ { "username": "USERNAME"} ]
}

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://api.bitbucket.org/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:

ParameterRequiredDescription
accountnameYesThe account owner.
repoYesThe repository name.

 

GET https://api.bitbucket.org/2.0/repositories/{username}/{repo-slug}/branch-restrictions
Click to expand and view a response...
{
    "page": 1, 
    "pagelen": 10, 
    "size": 3, 
    "values": [
        {
            "groups": [], 
            "id": 18, 
            "kind": "delete", 
            "links": [
                {
                    "href": "https://api.bitbucket.org/2.0/repositories/manthony/restrictiontest/branch-restrictions/18", 
                    "rel": "self"
                }, 
                {
                    "href": "https://api.bitbucket.org/2.0/repositories/manthony/restrictiontest/branch-restrictions", 
                    "rel": "parent"
                }
            ], 
            "pattern": "*zebra", 
            "users": []
        }, 
        {
            "groups": [], 
            "id": 32, 
            "kind": "force", 
            "links": [
                {
                    "href": "https://api.bitbucket.org/2.0/repositories/manthony/restrictiontest/branch-restrictions/32", 
                    "rel": "self"
                }, 
                {
                    "href": "https://api.bitbucket.org/2.0/repositories/manthony/restrictiontest/branch-restrictions", 
                    "rel": "parent"
                }
            ], 
            "pattern": "master", 
            "users": []
        }, 
        {
            "groups": [
                {
                    "full_slug": "bitbucket:developers", 
                    "links": [
                        {
                            "href": "/api/1.0/groups/bitbucket/developers", 
                            "rel": "self"
                        }
                    ], 
                    "name": "developers", 
                    "owner": {
                        "avatar_url": "https://secure.gravatar.com/avatar/14a1dfcf20cb05fbb75ea0a163d34acc?d=https%3A%2F%2Fd2isvjwd3d60f6.cloudfront.net%2Fm%2F6d9c8176bfd0%2Fimg%2Fdefault_team_avatar%2F32%2Fteam_blue.png&s=32", 
                        "display_name": "Bitbucket", 
                        "links": [
                            {
                                "href": "https://api.bitbucket.org/1.0/users/bitbucket", 
                                "rel": "self"
                            }, 
                            {
                                "href": "https://bitbucket.org/bitbucket", 
                                "rel": "html"
                            }
                        ], 
                        "username": "bitbucket"
                    }, 
                    "slug": "developers"
                }
            ], 
            "id": 33, 
            "kind": "push", 
            "links": [
                {
                    "href": "https://api.bitbucket.org/2.0/repositories/manthony/restrictiontest/branch-restrictions/33", 
                    "rel": "self"
                }, 
                {
                    "href": "https://api.bitbucket.org/2.0/repositories/manthony/restrictiontest/branch-restrictions", 
                    "rel": "parent"
                }
            ], 
            "pattern": "master", 
            "users": [
                {
                    "avatar_url": "https://bitbucket-staging-assetroot.s3.amazonaws.com/c/photos/2013/Jul/31/erik-avatar-725122544-0_avatar.png", 
                    "display_name": "Erik van Z\u0133st", 
                    "links": [
                        {
                            "href": "https://api.bitbucket.org/1.0/users/erik", 
                            "rel": "self"
                        }, 
                        {
                            "href": "https://bitbucket.org/erik", 
                            "rel": "html"
                        }
                    ], 
                    "username": "erik"
                }
            ]
        }
    ]
}

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:

ParameterRequiredDescription
username YesThe account owner (path parameter).
repo_slugYesThe repository name (path parameter).
groupsNoOne or more groups. This field is always empty for delete and force restrictions.
kindYes

Type of restriction. This can be one of:

  • push
  • delete
  • force 
patternNoA repository pattern to match. This is only required when kind is [. Accepts wildcards.
users NoAn array of user profiles corresponding to a set of users. This field is always empty for delete and force restrictions.
POST https://api.bitbucket.org/2.0/repositories/{username}/{repo_slug}/branch-restrictions --header 'Content-Type: application/json; charset=utf-8' --data @json.data
Example curl comand
curl -v -u tutorials https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/branch-restrictions --header "Content-Type: application/json" --data 
Example: body of call to add user branch restriction
{
    "groups": [],
    "kind": "push",
    "pattern": "Tutorial-test-restrict",
    "users": [{
        "username": "tutorials"
    }]
} 
Response from add user branch restriction call
{
    "groups": [],
    "id": 152688,
    "kind": "push",
    "links": {
        "parent": {
            "href": "https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/branch-restrictions"
        },
        "self": {
            "href": "https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/branch-restrictions/152688"
        }
    },
    "pattern": "Tutorial-test-restrict",
    "users": [
        {
            "display_name": "tutorials account",
            "links": {
                "avatar": {
                    "href": "https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2013/Nov/25/tutorials-avatar-1563784409-6_avatar.png"
                },
                "self": {
                    "href": "https://api.bitbucket.org/2.0/users/tutorials"
                }
            },
            "username": "tutorials"
        }
    ]
}
Example: body of call to add group branch restriction
{
    "groups": [
               {
               "full_slug": "tutorials:team-from-space",
               "name": "team-from-space",
               "owner": {
               "username": "tutorials"
               },
               "slug": "team-from-space"
               }
               ],
    "kind": "push",
    "pattern": "Tutorial-test-restrict",
    "users": []
}
Response from add group branch restriction call
{
    "groups": [
        {
            "full_slug": "tutorials:team-from-space",
            "links": {
                "self": {
                    "href": "https://api.bitbucket.org/1.0/groups/tutorials/team-from-space"
                }
            },
            "name": "team-from-space",
            "owner": {
                "display_name": "tutorials account",
                "links": {
                    "avatar": {
                        "href": "https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2013/Nov/25/tutorials-avatar-1563784409-6_avatar.png"
                    },
                    "self": {
                        "href": "https://api.bitbucket.org/2.0/users/tutorials"
                    }
                },
                "username": "tutorials"
            },
            "slug": "team-from-space"
        }
    ],
    "id": 152748,
    "kind": "push",
    "links": {
        "parent": {
            "href": "https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/branch-restrictions"
        },
        "self": {
            "href": "https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/branch-restrictions/152748"
        }
    },
    "pattern": "Tutorial-test-restrict",
    "users": []
}

GET a specific restriction

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

ParameterRequiredDescription
accountnameYesThe account owner.
repoYesThe repository name.
idYesThe restriction's identifier.
GET https://api.bitbucket.org/2.0/repositories/{username}/{repo-slug}/branch-restrictions/{id}
Click to expand and view a response...
{
    "groups": [], 
    "id": 52, 
    "kind": "delete", 
    "links": [
        {
            "href": "https://api.bitbucket.org/2.0/repositories/manthony/restrictiontest/branch-restrictions/52", 
            "rel": "self"
        }, 
        {
            "href": "https://api.bitbucket.org/2.0/repositories/manthony/restrictiontest/branch-restrictions", 
            "rel": "parent"
        }
    ], 
    "pattern": "foobar/*", 
    "users": []
}

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:

ParameterRequiredDescription
accountnameYesThe account owner.
repoYesThe repository name.
groupsNoOne or more groups. This field is always empty for delete and force restrictions.
idYesThe restriction identifier.
patternNoA repository pattern to match. This is only required when kind is push. Accepts wildcards.
usersNoAn array of user profiles corresponding to a set of users. This field is always empty for delete and force restrictions.
PUT https://api.bitbucket.org/2.0/repositories/{username}/{repo-slug}/branch-restrictions/{id}
Click to expand and view a response...
{
    "groups": [], 
    "id": 52, 
    "kind": "delete", 
    "links": [
        {
            "href": "https://api.bitbucket.org/2.0/repositories/manthony/restrictiontest/branch-restrictions/52", 
            "rel": "self"
        }, 
        {
            "href": "https://api.bitbucket.org/2.0/repositories/manthony/restrictiontest/branch-restrictions", 
            "rel": "parent"
        }
    ], 
    "pattern": "foobar/*", 
    "users": []
}

DELETE the branch restriction

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

ParameterRequiredDescription
accountnameYesThe account owner.
repoYesThe repository name.
idYesThe restriction identifier.
DELETE https://api.bitbucket.org/2.0/repositories/{username}/{repo-slug}/branch-restrictions/{id}
Last modified on Jun 24, 2020

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.