KV
List
Returns the namespaces owned by an account.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account identifier. | |
params | array | No | [] | Array containing the necessary params. |
$response = $client->kv()->list('ACCOUNT_ID', []);
Create
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.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account identifier. | |
title | string | Yes | A human-readable string name for a Namespace. |
$response = $client->kv()->create('ACCOUNT_ID', 'TITLE');
Get
Get the namespace corresponding to the given ID.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account identifier. | |
namespaceId | string | Yes | Namespace identifier tag. |
$response = $client->kv()->get('ACCOUNT_ID', 'NAMESPACE_ID');
Update
Modifies a namespace's title.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account identifier. | |
namespaceId | string | Yes | Namespace identifier tag. | |
title | string | Yes | A human-readable string name for a Namespace. |
$response = $client->kv()->update('ACCOUNT_ID', 'NAMESPACE_ID', 'TITLE');
Delete
Deletes the namespace corresponding to the given ID.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account identifier. | |
namespaceId | string | Yes | Namespace identifier tag. |
$response = $client->kv()->delete('ACCOUNT_ID', 'NAMESPACE_ID');
List Keys
Lists a namespace keys.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account identifier. | |
namespaceId | string | Yes | Namespace identifier tag. | |
params | array | No | [] | Array containing the necessary params. |
$response = $client->kv()->listKeys('ACCOUNT_ID', 'NAMESPACE_ID', []);
Key Metadata
Returns the metadata associated with the given key in the given namespace. Use URL-encoding to use special characters (for example, :, !, %) in the key name.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account identifier. | |
namespaceId | string | Yes | Namespace identifier tag. | |
keyName | string | Yes | A key's name. The name may be at most 512 bytes. All printable, non-whitespace characters are valid. Use percent-encoding to define key names as part of a URL. |
$response = $client->kv()->keyMetadata('ACCOUNT_ID', 'NAMESPACE_ID', 'KEY_NAME');
Key Details
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.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account identifier. | |
namespaceId | string | Yes | Namespace identifier tag. | |
keyName | string | Yes | A key's name. The name may be at most 512 bytes. All printable, non-whitespace characters are valid. Use percent-encoding to define key names as part of a URL. |
$response = $client->kv()->keyDetails('ACCOUNT_ID', 'NAMESPACE_ID', 'KEY_NAME');
Write Key With Metadata
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 along with JSON metadata to be associated with the key/value pair.
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.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account identifier. | |
namespaceId | string | Yes | Namespace identifier tag. | |
keyName | string | Yes | A key's name. The name may be at most 512 bytes. All printable, non-whitespace characters are valid. Use percent-encoding to define key names as part of a URL. | |
values | array | Yes | keys and values. |
$response = $client->kv()->writeKeyWithMetadata('ACCOUNT_ID', 'NAMESPACE_ID', 'KEY_NAME', []);
Delete Key
Remove multiple KV pairs from the namespace. Body should be an array of up to 10,000 keys to be removed.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account identifier. | |
namespaceId | string | Yes | Namespace identifier tag. | |
keyName | string | Yes | A key's name. The name may be at most 512 bytes. All printable, non-whitespace characters are valid. Use percent-encoding to define key names as part of a URL. |
$response = $client->kv()->deleteKey('ACCOUNT_ID', 'NAMESPACE_ID', 'KEY_NAME');
Write Multiple Keys
Write multiple keys and values at once. Body should be an array of up to 10,000 key-value pairs to be stored, along with optional expiration information.
Existing values and expirations 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. The entire request size must be 100 megabytes or less.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account identifier. | |
namespaceId | string | Yes | Namespace identifier tag. | |
values | array | Yes | keys and values. |
$response = $client->kv()->writeMultipleKeys('ACCOUNT_ID', 'NAMESPACE_ID', []);
Delete Multiple Keys
Remove multiple KV pairs from the namespace. Body should be an array of up to 10,000 keys to be removed.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account identifier. | |
namespaceId | string | Yes | Namespace identifier tag. | |
keys | array | Yes | Keys. |
$response = $client->kv()->deleteMultipleKeys('ACCOUNT_ID', 'NAMESPACE_ID', []);
Get Multiple Keys
Read multiple KV pairs from the namespace, up to 100 at a time. The values must be text-based.
Unlike the other bulk operations, which take up to 10,000 keys, this one
is capped at 100. Values come back as strings unless type is json, in
which case Cloudflare parses them for you.
$client->kv()->getMultipleKeys('ACCOUNT_ID', 'NAMESPACE_ID', ['key-a', 'key-b'], 'json', true);
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account identifier. | |
namespaceId | string | Yes | Namespace identifier tag. | |
keys | array | Yes | Keys to retrieve, at most 100 of them. | |
type | string | No | 'text' | Whether to parse JSON values in the response: `text` or `json`. |
withMetadata | bool | No | false | Whether to include each key's metadata in the response. |
$response = $client->kv()->getMultipleKeys('ACCOUNT_ID', 'NAMESPACE_ID', [], 'TYPE', true);

