Skip to main content

values

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

Overview

Namevalues
TypeResource
Idcloudflare.kv.values

Fields

The following fields are returned by SELECT queries:

Read key-value pair response.

NameDatatypeDescription
contentsstring

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectkey_name, namespace_id, account_idReturns the value associated with the given key in the given namespace. Use URL-encoding to use special characters (for example, :, !, %) in the key name. If the KV-pair is set to expire at some point, the expiration time as measured in seconds since the UNIX epoch will be returned in the expiration response header.
updatereplacekey_name, namespace_id, account_idexpiration, expiration_ttlWrite a value identified by a key. Use URL-encoding to use special characters (for example, :, !, %) in the key name. Body should be the value to be stored. If JSON metadata to be associated with the key/value pair is needed, use multipart/form-data content type for your PUT request (see dropdown below in REQUEST BODY SCHEMA). Existing values, expirations, and metadata will be overwritten. If neither expiration nor expiration_ttl is specified, the key-value pair will never expire. If both are set, expiration_ttl is used and expiration is ignored.
deletedeletekey_name, namespace_id, account_idRemove a KV pair from the namespace. Use URL-encoding to use special characters (for example, :, !, %) in the key name.

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.
key_namestring
namespace_idstringThe Workers KV namespace ID.
expirationnumber
expiration_ttlnumber

SELECT examples

Returns the value associated with the given key in the given namespace. Use URL-encoding to use special characters (for example, :, !, %) in the key name. If the KV-pair is set to expire at some point, the expiration time as measured in seconds since the UNIX epoch will be returned in the expiration response header.

SELECT
contents
FROM cloudflare.kv.values
WHERE key_name = '{{ key_name }}' -- required
AND namespace_id = '{{ namespace_id }}' -- required
AND account_id = '{{ account_id }}' -- required
;

REPLACE examples

Write a value identified by a key. Use URL-encoding to use special characters (for example, :, !, %) in the key name. Body should be the value to be stored. If JSON metadata to be associated with the key/value pair is needed, use multipart/form-data content type for your PUT request (see dropdown below in REQUEST BODY SCHEMA). Existing values, expirations, and metadata will be overwritten. If neither expiration nor expiration_ttl is specified, the key-value pair will never expire. If both are set, expiration_ttl is used and expiration is ignored.

REPLACE cloudflare.kv.values
SET
-- No updatable properties
WHERE
key_name = '{{ key_name }}' --required
AND namespace_id = '{{ namespace_id }}' --required
AND account_id = '{{ account_id }}' --required
AND expiration = '{{ expiration}}'
AND expiration_ttl = '{{ expiration_ttl}}'
RETURNING
errors,
messages,
result,
success;

DELETE examples

Remove a KV pair from the namespace. Use URL-encoding to use special characters (for example, :, !, %) in the key name.

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