Addon
Branch restrictions
Branching model
Commit statuses
Commits
Deployments
Downloads
Issue tracker
Pipelines
Projects
Pullrequests
Refs
Reports
Repositories
Snippets
Source
Ssh
Teams
Users
Webhooks
Workspaces
Other operations

Rate this page:

Snippets

Snippets allow you share code segments or files with yourself, members of your workspace, or the world.

Like pull requests, repositories and workspaces, the full set of snippets is defined by what the current user has access to. This includes all snippets owned by any of the workspaces the user is a member of, or snippets by other users that the current user is either watching or has collaborated on (for instance by commenting on it).

List snippets

GET /2.0/snippets

Returns all snippets. Like pull requests, repositories and workspaces, the full set of snippets is defined by what the current user has access to.

This includes all snippets owned by any of the workspaces the user is a member of, or snippets by other users that the current user is either watching or has collaborated on (for instance by commenting on it).

To limit the set of returned snippets, apply the ?role=[owner|contributor|member] query parameter where the roles are defined as follows:

  • owner: all snippets owned by the current user
  • contributor: all snippets owned by, or watched by the current user
  • member: created in a workspaces or watched by the current user

When no role is specified, all public snippets are returned, as well as all privately owned snippets watched or commented on.

The returned response is a normal paginated JSON list. This endpoint only supports application/json responses and no multipart/form-data or multipart/related. As a result, it is not possible to include the file contents.

OAuth scopes required
snippet

Request

Query parameters
role

string

Filter down the result based on the authenticated user's role (owner, contributor, or member).

Valid values: owner, contributor, member

Example

1
2
3
4
curl --request GET \
  --url 'https://api.bitbucket.org/2.0/snippets' \
  --header 'Authorization: Bearer <access_token>' \
  --header 'Accept: application/json'

Responses

A paginated list of snippets.

Content typeValue
application/json

Paginated Snippets

Create a snippet

POST /2.0/snippets

Creates a new snippet under the authenticated user's account.

Snippets can contain multiple files. Both text and binary files are supported.

The simplest way to create a new snippet from a local file:

1
$ curl -u username:password -X POST https://api.bitbucket.org/2.0/snippets               -F file=@image.png

Creating snippets through curl has a few limitations and so let's look at a more complicated scenario.

Snippets are created with a multipart POST. Both multipart/form-data and multipart/related are supported. Both allow the creation of snippets with both meta data (title, etc), as well as multiple text and binary files.

The main difference is that multipart/related can use rich encoding for the meta data (currently JSON).