A newer version of this documentation is available.

View Latest

Creating a Scope

  • reference

Couchbase Server Enterprise Edition 7.6 reaches End of Life on March 31, 2027. Please upgrade to 8.0.x by following Upgrade, or contact Couchbase Support.

Scopes can be created, by means of the REST API.

Description

Scopes are created by means of the POST /pools/default/buckets/<bucket_name>/scopes/ HTTP method and URI.

HTTP Method and URI

POST /pools/default/buckets/<bucket_name>/scopes

Curl Syntax

The curl syntax is as follows:

curl -X POST -v -u [admin]:[password]
  http://<hostname-or-ip>:8091/pools/default/buckets/<bucket-name>/scopes
  -d name=<scope-name>

The <bucket-name> path-parameter specifies the bucket within which the new scope is to be created. The name parameter specifies the name of the scope to be created: this name cannot subsequently be changed.

Responses

Success returns 200 OK. Failure to authenticate gives 401 Unauthorized. A malformed URI fails with 404 Object Not Found. If the scope-name is improperly specified, a notification such as "name":"Length must be in range from 1 to 30" or "name":"Can only contain characters A-Z, a-z, 0-9 and the following symbols _ - %" is displayed. See Naming for Scopes and Collections, for an account of naming conventions.

Example

The following call creates a scope named my_scope in the bucket testBucket:

curl -X POST -v -u Administrator:password \
http://10.143.210.101:8091/pools/default/buckets/testBucket/scopes \
-d name=my_scope

If successful, the call returns a uid, such as the following:

{"uid":17}

See Also

An overview of scopes and collections is provided in Scopes and Collections. Step-by-step procedures for management are provided in Manage Scopes and Collections. See also the CLI reference page for the collection-manage command.