Skip to main content

namespaces

Creates, updates, deletes, gets or lists a namespaces resource.

Overview

Namenamespaces
TypeResource
Idcloudflare.kv.namespaces

Fields

The following fields are returned by SELECT queries:

Get a Namespace response.

NameDatatypeDescription
idstringNamespace identifier tag. (example: 0f2ac74b498b48028cb68387c421e279)
supports_url_encodingbooleanTrue if keys written on the URL will be URL-decoded before storing. For example, if set to "true", a key written on the URL as "%3F" will be stored as "?".
titlestringA human-readable string name for a Namespace. (example: My Own Namespace)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectnamespace_id, account_idGet the namespace corresponding to the given ID.
listselectaccount_idpage, per_page, order, directionReturns the namespaces owned by an account.
createinsertaccount_id, titleCreates a namespace under the given title. A 400 is returned if the account already owns a namespace with this title. A namespace must be explicitly deleted to be replaced.
updatereplacenamespace_id, account_id, titleModifies a namespace's title.
deletedeletenamespace_id, account_idDeletes the namespace corresponding to the given ID.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
account_idstringThe Cloudflare account ID.
namespace_idstringThe Workers KV namespace ID.
directionstring
orderstring
pagenumber
per_pagenumber

SELECT examples

Get the namespace corresponding to the given ID.

SELECT
id,
supports_url_encoding,
title
FROM cloudflare.kv.namespaces
WHERE namespace_id = '{{ namespace_id }}' -- required
AND account_id = '{{ account_id }}' -- required
;

INSERT examples

Creates a namespace under the given title. A 400 is returned if the account already owns a namespace with this title. A namespace must be explicitly deleted to be replaced.

INSERT INTO cloudflare.kv.namespaces (
title,
account_id
)
SELECT
'{{ title }}' /* required */,
'{{ account_id }}'
RETURNING
errors,
messages,
result,
success
;

REPLACE examples

Modifies a namespace's title.

REPLACE cloudflare.kv.namespaces
SET
title = '{{ title }}'
WHERE
namespace_id = '{{ namespace_id }}' --required
AND account_id = '{{ account_id }}' --required
AND title = '{{ title }}' --required
RETURNING
errors,
messages,
result,
success;

DELETE examples

Deletes the namespace corresponding to the given ID.

DELETE FROM cloudflare.kv.namespaces
WHERE namespace_id = '{{ namespace_id }}' --required
AND account_id = '{{ account_id }}' --required
;