# Namespaces ## List Namespaces `client.kv.namespaces.list(NamespaceListParamsparams, RequestOptionsoptions?): V4PagePaginationArray` **get** `/accounts/{account_id}/storage/kv/namespaces` Returns the namespaces owned by an account. ### Parameters - `params: NamespaceListParams` - `account_id: string` Path param: Identifier. - `direction?: "asc" | "desc"` Query param: Direction to order namespaces. - `"asc"` - `"desc"` - `order?: "id" | "title"` Query param: Field to order results by. - `"id"` - `"title"` - `page?: number` Query param: Page number of paginated results. - `per_page?: number` Query param: Maximum number of results per page. ### Returns - `Namespace` - `id: string` Namespace identifier tag. - `title: string` A human-readable string name for a Namespace. - `supports_url_encoding?: boolean` True 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 "?". ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const namespace of client.kv.namespaces.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', })) { console.log(namespace.id); } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": [ { "id": "0f2ac74b498b48028cb68387c421e279", "title": "My Own Namespace", "supports_url_encoding": true } ], "result_info": { "count": 1, "page": 1, "per_page": 20, "total_count": 2000 } } ``` ## Get a Namespace `client.kv.namespaces.get(stringnamespaceId, NamespaceGetParamsparams, RequestOptionsoptions?): Namespace` **get** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}` Get the namespace corresponding to the given ID. ### Parameters - `namespaceId: string` Namespace identifier tag. - `params: NamespaceGetParams` - `account_id: string` Identifier. ### Returns - `Namespace` - `id: string` Namespace identifier tag. - `title: string` A human-readable string name for a Namespace. - `supports_url_encoding?: boolean` True 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 "?". ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const namespace = await client.kv.namespaces.get('0f2ac74b498b48028cb68387c421e279', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(namespace.id); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "id": "0f2ac74b498b48028cb68387c421e279", "title": "My Own Namespace", "supports_url_encoding": true } } ``` ## Create a Namespace `client.kv.namespaces.create(NamespaceCreateParamsparams, RequestOptionsoptions?): Namespace` **post** `/accounts/{account_id}/storage/kv/namespaces` 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. ### Parameters - `params: NamespaceCreateParams` - `account_id: string` Path param: Identifier. - `title: string` Body param: A human-readable string name for a Namespace. ### Returns - `Namespace` - `id: string` Namespace identifier tag. - `title: string` A human-readable string name for a Namespace. - `supports_url_encoding?: boolean` True 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 "?". ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const namespace = await client.kv.namespaces.create({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', title: 'My Own Namespace', }); console.log(namespace.id); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "id": "0f2ac74b498b48028cb68387c421e279", "title": "My Own Namespace", "supports_url_encoding": true } } ``` ## Rename a Namespace `client.kv.namespaces.update(stringnamespaceId, NamespaceUpdateParamsparams, RequestOptionsoptions?): Namespace` **put** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}` Modifies a namespace's title. ### Parameters - `namespaceId: string` Namespace identifier tag. - `params: NamespaceUpdateParams` - `account_id: string` Path param: Identifier. - `title: string` Body param: A human-readable string name for a Namespace. ### Returns - `Namespace` - `id: string` Namespace identifier tag. - `title: string` A human-readable string name for a Namespace. - `supports_url_encoding?: boolean` True 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 "?". ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const namespace = await client.kv.namespaces.update('0f2ac74b498b48028cb68387c421e279', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', title: 'My Own Namespace', }); console.log(namespace.id); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "id": "0f2ac74b498b48028cb68387c421e279", "title": "My Own Namespace", "supports_url_encoding": true }, "success": true } ``` ## Remove a Namespace `client.kv.namespaces.delete(stringnamespaceId, NamespaceDeleteParamsparams, RequestOptionsoptions?): NamespaceDeleteResponse | null` **delete** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}` Deletes the namespace corresponding to the given ID. ### Parameters - `namespaceId: string` Namespace identifier tag. - `params: NamespaceDeleteParams` - `account_id: string` Identifier. ### Returns - `NamespaceDeleteResponse` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const namespace = await client.kv.namespaces.delete('0f2ac74b498b48028cb68387c421e279', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(namespace); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": {} } ``` ## Write multiple key-value pairs `client.kv.namespaces.bulkUpdate(stringnamespaceId, NamespaceBulkUpdateParamsparams, RequestOptionsoptions?): NamespaceBulkUpdateResponse | null` **put** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/bulk` 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. ### Parameters - `namespaceId: string` Namespace identifier tag. - `params: NamespaceBulkUpdateParams` - `account_id: string` Path param: Identifier. - `body: Array` Body param - `key: string` A key's name. The name may be at most 512 bytes. All printable, non-whitespace characters are valid. - `value: string` A UTF-8 encoded string to be stored, up to 25 MiB in length. - `base64?: boolean` Indicates whether or not the server should base64 decode the value before storing it. Useful for writing values that wouldn't otherwise be valid JSON strings, such as images. - `expiration?: number` Expires the key at a certain time, measured in number of seconds since the UNIX epoch. - `expiration_ttl?: number` Expires the key after a number of seconds. Must be at least 60. - `metadata?: unknown` Arbitrary JSON that is associated with a key. ### Returns - `NamespaceBulkUpdateResponse` - `successful_key_count?: number` Number of keys successfully updated. - `unsuccessful_keys?: Array` Name of the keys that failed to be fully updated. They should be retried. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.kv.namespaces.bulkUpdate('0f2ac74b498b48028cb68387c421e279', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', body: [{ key: 'My-Key', value: 'Some string' }], }); console.log(response.successful_key_count); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "successful_key_count": 100, "unsuccessful_keys": [ "string" ] } } ``` ## Delete multiple key-value pairs `client.kv.namespaces.bulkDelete(stringnamespaceId, NamespaceBulkDeleteParamsparams, RequestOptionsoptions?): NamespaceBulkDeleteResponse | null` **post** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/bulk/delete` Remove multiple KV pairs from the namespace. Body should be an array of up to 10,000 keys to be removed. ### Parameters - `namespaceId: string` Namespace identifier tag. - `params: NamespaceBulkDeleteParams` - `account_id: string` Path param: Identifier. - `body: Array` Body param ### Returns - `NamespaceBulkDeleteResponse` - `successful_key_count?: number` Number of keys successfully updated. - `unsuccessful_keys?: Array` Name of the keys that failed to be fully updated. They should be retried. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.kv.namespaces.bulkDelete('0f2ac74b498b48028cb68387c421e279', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', body: ['My-Key'], }); console.log(response.successful_key_count); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "successful_key_count": 100, "unsuccessful_keys": [ "string" ] } } ``` ## Get multiple key-value pairs `client.kv.namespaces.bulkGet(stringnamespaceId, NamespaceBulkGetParamsparams, RequestOptionsoptions?): NamespaceBulkGetResponse | null` **post** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/bulk/get` Retrieve up to 100 KV pairs from the namespace. Keys must contain text-based values. JSON values can optionally be parsed instead of being returned as a string value. Metadata can be included if `withMetadata` is true. ### Parameters - `namespaceId: string` Namespace identifier tag. - `params: NamespaceBulkGetParams` - `account_id: string` Path param: Identifier. - `keys: Array` Body param: Array of keys to retrieve (maximum of 100). - `type?: "text" | "json"` Body param: Whether to parse JSON values in the response. - `"text"` - `"json"` - `withMetadata?: boolean` Body param: Whether to include metadata in the response. ### Returns - `NamespaceBulkGetResponse = WorkersKVBulkGetResult | WorkersKVBulkGetResultWithMetadata | null` - `WorkersKVBulkGetResult` - `values?: Record>` Requested keys are paired with their values in an object. - `string` - `number` - `boolean` - `Record` - `WorkersKVBulkGetResultWithMetadata` - `values?: Record` Requested keys are paired with their values and metadata in an object. - `metadata: unknown` The metadata associated with the key. - `value: unknown` The value associated with the key. - `expiration?: number` Expires the key at a certain time, measured in number of seconds since the UNIX epoch. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.kv.namespaces.bulkGet('0f2ac74b498b48028cb68387c421e279', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', keys: ['My-Key'], }); console.log(response); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "values": { "key1": "value1", "key2": "value2" } } } ``` ## Domain Types ### Namespace - `Namespace` - `id: string` Namespace identifier tag. - `title: string` A human-readable string name for a Namespace. - `supports_url_encoding?: boolean` True 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 "?". ### Namespace Delete Response - `NamespaceDeleteResponse` ### Namespace Bulk Update Response - `NamespaceBulkUpdateResponse` - `successful_key_count?: number` Number of keys successfully updated. - `unsuccessful_keys?: Array` Name of the keys that failed to be fully updated. They should be retried. ### Namespace Bulk Delete Response - `NamespaceBulkDeleteResponse` - `successful_key_count?: number` Number of keys successfully updated. - `unsuccessful_keys?: Array` Name of the keys that failed to be fully updated. They should be retried. ### Namespace Bulk Get Response - `NamespaceBulkGetResponse = WorkersKVBulkGetResult | WorkersKVBulkGetResultWithMetadata | null` - `WorkersKVBulkGetResult` - `values?: Record>` Requested keys are paired with their values in an object. - `string` - `number` - `boolean` - `Record` - `WorkersKVBulkGetResultWithMetadata` - `values?: Record` Requested keys are paired with their values and metadata in an object. - `metadata: unknown` The metadata associated with the key. - `value: unknown` The value associated with the key. - `expiration?: number` Expires the key at a certain time, measured in number of seconds since the UNIX epoch. # Keys ## List a Namespace's Keys `client.kv.namespaces.keys.list(stringnamespaceId, KeyListParamsparams, RequestOptionsoptions?): CursorLimitPagination` **get** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/keys` Lists a namespace's keys. ### Parameters - `namespaceId: string` Namespace identifier tag. - `params: KeyListParams` - `account_id: string` Path param: Identifier. - `cursor?: string` Query param: Opaque token indicating the position from which to continue when requesting the next set of records if the amount of list results was limited by the limit parameter. A valid value for the cursor can be obtained from the `cursors` object in the `result_info` structure. - `limit?: number` Query param: Limits the number of keys returned in the response. The cursor attribute may be used to iterate over the next batch of keys if there are more than the limit. - `prefix?: string` Query param: Filters returned keys by a name prefix. Exact matches and any key names that begin with the prefix will be returned. ### Returns - `Key` A name for a value. A value stored under a given key may be retrieved via the same key. - `name: string` 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. - `expiration?: number` The time, measured in number of seconds since the UNIX epoch, at which the key will expire. This property is omitted for keys that will not expire. - `metadata?: unknown` Arbitrary JSON that is associated with a key. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const key of client.kv.namespaces.keys.list('0f2ac74b498b48028cb68387c421e279', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', })) { console.log(key.name); } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": [ { "name": "My-Key", "expiration": 1577836800, "metadata": {} } ], "result_info": { "count": 1, "cursor": "6Ck1la0VxJ0djhidm1MdX2FyDGxLKVeeHZZmORS_8XeSuhz9SjIJRaSa2lnsF01tQOHrfTGAP3R5X1Kv5iVUuMbNKhWNAXHOl6ePB0TUL8nw" } } ``` ## Write multiple key-value pairs `client.kv.namespaces.keys.bulkUpdate(stringnamespaceId, KeyBulkUpdateParamsparams, RequestOptionsoptions?): KeyBulkUpdateResponse | null` **put** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/bulk` 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. ### Parameters - `namespaceId: string` Namespace identifier tag. - `params: KeyBulkUpdateParams` - `account_id: string` Path param: Identifier. - `body: Array` Body param - `key: string` A key's name. The name may be at most 512 bytes. All printable, non-whitespace characters are valid. - `value: string` A UTF-8 encoded string to be stored, up to 25 MiB in length. - `base64?: boolean` Indicates whether or not the server should base64 decode the value before storing it. Useful for writing values that wouldn't otherwise be valid JSON strings, such as images. - `expiration?: number` Expires the key at a certain time, measured in number of seconds since the UNIX epoch. - `expiration_ttl?: number` Expires the key after a number of seconds. Must be at least 60. - `metadata?: unknown` Arbitrary JSON that is associated with a key. ### Returns - `KeyBulkUpdateResponse` - `successful_key_count?: number` Number of keys successfully updated. - `unsuccessful_keys?: Array` Name of the keys that failed to be fully updated. They should be retried. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.kv.namespaces.keys.bulkUpdate('0f2ac74b498b48028cb68387c421e279', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', body: [{ key: 'My-Key', value: 'Some string' }], }); console.log(response.successful_key_count); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "successful_key_count": 100, "unsuccessful_keys": [ "string" ] } } ``` ## Delete multiple key-value pairs `client.kv.namespaces.keys.bulkDelete(stringnamespaceId, KeyBulkDeleteParamsparams, RequestOptionsoptions?): KeyBulkDeleteResponse | null` **post** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/bulk/delete` Remove multiple KV pairs from the namespace. Body should be an array of up to 10,000 keys to be removed. ### Parameters - `namespaceId: string` Namespace identifier tag. - `params: KeyBulkDeleteParams` - `account_id: string` Path param: Identifier. - `body: Array` Body param ### Returns - `KeyBulkDeleteResponse` - `successful_key_count?: number` Number of keys successfully updated. - `unsuccessful_keys?: Array` Name of the keys that failed to be fully updated. They should be retried. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.kv.namespaces.keys.bulkDelete('0f2ac74b498b48028cb68387c421e279', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', body: ['My-Key'], }); console.log(response.successful_key_count); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "successful_key_count": 100, "unsuccessful_keys": [ "string" ] } } ``` ## Get multiple key-value pairs `client.kv.namespaces.keys.bulkGet(stringnamespaceId, KeyBulkGetParamsparams, RequestOptionsoptions?): KeyBulkGetResponse | null` **post** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/bulk/get` Retrieve up to 100 KV pairs from the namespace. Keys must contain text-based values. JSON values can optionally be parsed instead of being returned as a string value. Metadata can be included if `withMetadata` is true. ### Parameters - `namespaceId: string` Namespace identifier tag. - `params: KeyBulkGetParams` - `account_id: string` Path param: Identifier. - `keys: Array` Body param: Array of keys to retrieve (maximum of 100). - `type?: "text" | "json"` Body param: Whether to parse JSON values in the response. - `"text"` - `"json"` - `withMetadata?: boolean` Body param: Whether to include metadata in the response. ### Returns - `KeyBulkGetResponse = WorkersKVBulkGetResult | WorkersKVBulkGetResultWithMetadata | null` - `WorkersKVBulkGetResult` - `values?: Record>` Requested keys are paired with their values in an object. - `string` - `number` - `boolean` - `Record` - `WorkersKVBulkGetResultWithMetadata` - `values?: Record` Requested keys are paired with their values and metadata in an object. - `metadata: unknown` The metadata associated with the key. - `value: unknown` The value associated with the key. - `expiration?: number` Expires the key at a certain time, measured in number of seconds since the UNIX epoch. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.kv.namespaces.keys.bulkGet('0f2ac74b498b48028cb68387c421e279', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', keys: ['My-Key'], }); console.log(response); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "values": { "key1": "value1", "key2": "value2" } } } ``` ## Domain Types ### Key - `Key` A name for a value. A value stored under a given key may be retrieved via the same key. - `name: string` 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. - `expiration?: number` The time, measured in number of seconds since the UNIX epoch, at which the key will expire. This property is omitted for keys that will not expire. - `metadata?: unknown` Arbitrary JSON that is associated with a key. ### Key Bulk Update Response - `KeyBulkUpdateResponse` - `successful_key_count?: number` Number of keys successfully updated. - `unsuccessful_keys?: Array` Name of the keys that failed to be fully updated. They should be retried. ### Key Bulk Delete Response - `KeyBulkDeleteResponse` - `successful_key_count?: number` Number of keys successfully updated. - `unsuccessful_keys?: Array` Name of the keys that failed to be fully updated. They should be retried. ### Key Bulk Get Response - `KeyBulkGetResponse = WorkersKVBulkGetResult | WorkersKVBulkGetResultWithMetadata | null` - `WorkersKVBulkGetResult` - `values?: Record>` Requested keys are paired with their values in an object. - `string` - `number` - `boolean` - `Record` - `WorkersKVBulkGetResultWithMetadata` - `values?: Record` Requested keys are paired with their values and metadata in an object. - `metadata: unknown` The metadata associated with the key. - `value: unknown` The value associated with the key. - `expiration?: number` Expires the key at a certain time, measured in number of seconds since the UNIX epoch. # Metadata ## Read the metadata for a key `client.kv.namespaces.metadata.get(stringnamespaceId, stringkeyName, MetadataGetParamsparams, RequestOptionsoptions?): MetadataGetResponse` **get** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/metadata/{key_name}` 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. ### Parameters - `namespaceId: string` Namespace identifier tag. - `keyName: string` 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. - `params: MetadataGetParams` - `account_id: string` Identifier. ### Returns - `MetadataGetResponse = unknown` Arbitrary JSON that is associated with a key. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const metadata = await client.kv.namespaces.metadata.get( '0f2ac74b498b48028cb68387c421e279', 'My-Key', { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, ); console.log(metadata); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": {} } ``` ## Domain Types ### Metadata Get Response - `MetadataGetResponse = unknown` Arbitrary JSON that is associated with a key. # Values ## Read key-value pair `client.kv.namespaces.values.get(stringnamespaceId, stringkeyName, ValueGetParamsparams, RequestOptionsoptions?): Response` **get** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/values/{key_name}` 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. ### Parameters - `namespaceId: string` Namespace identifier tag. - `keyName: string` 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. - `params: ValueGetParams` - `account_id: string` Identifier. ### Returns - `unnamed_schema_1 = Response` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const value = await client.kv.namespaces.values.get('0f2ac74b498b48028cb68387c421e279', 'My-Key', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(value); const content = await value.blob(); console.log(content); ``` ## Write key-value pair with optional metadata `client.kv.namespaces.values.update(stringnamespaceId, stringkeyName, ValueUpdateParamsparams, RequestOptionsoptions?): ValueUpdateResponse | null` **put** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/values/{key_name}` 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. ### Parameters - `namespaceId: string` Namespace identifier tag. - `keyName: string` 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. - `params: ValueUpdateParams` - `account_id: string` Path param: Identifier. - `value: string | Uploadable` Body param: A byte sequence to be stored, up to 25 MiB in length. - `string` - `Uploadable` - `expiration?: number` Query param: Expires the key at a certain time, measured in number of seconds since the UNIX epoch. - `expiration_ttl?: number` Query param: Expires the key after a number of seconds. Must be at least 60. - `metadata?: unknown` Body param: Associates arbitrary JSON data with a key/value pair. ### Returns - `ValueUpdateResponse` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const value = await client.kv.namespaces.values.update( '0f2ac74b498b48028cb68387c421e279', 'My-Key', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', value: 'Some Value' }, ); console.log(value); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": {} } ``` ## Delete key-value pair `client.kv.namespaces.values.delete(stringnamespaceId, stringkeyName, ValueDeleteParamsparams, RequestOptionsoptions?): ValueDeleteResponse | null` **delete** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/values/{key_name}` Remove a KV pair from the namespace. Use URL-encoding to use special characters (for example, `:`, `!`, `%`) in the key name. ### Parameters - `namespaceId: string` Namespace identifier tag. - `keyName: string` 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. - `params: ValueDeleteParams` - `account_id: string` Identifier. ### Returns - `ValueDeleteResponse` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const value = await client.kv.namespaces.values.delete( '0f2ac74b498b48028cb68387c421e279', 'My-Key', { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, ); console.log(value); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": {} } ``` ## Domain Types ### Value Update Response - `ValueUpdateResponse` ### Value Delete Response - `ValueDeleteResponse`