---
title: Write multiple key-value pairs
---

[Skip to content](#_top)

[API Reference](https://developers.cloudflare.com/api/go)

[KV](https://developers.cloudflare.com/api/go/resources/kv)

[Namespaces](https://developers.cloudflare.com/api/go/resources/kv/subresources/namespaces)

Copy Markdown

Open in **Claude**Open in **ChatGPT**Open in **Cursor**

---

**Copy Markdown****View as Markdown**

# Write multiple key-value pairs

client.KV.Namespaces.BulkUpdate(ctx, namespaceID, params) (\*[NamespaceBulkUpdateResponse](<https://developers.cloudflare.com/api/go/resources/kv#(resource)%20kv.namespaces%20%3E%20(model)%20NamespaceBulkUpdateResponse%20%3E%20(schema)>), error)

PUT/accounts/{account\_id}/storage/kv/namespaces/{namespace\_id}/bulk

Writes up to 10,000 key-value pairs to the specified Workers KV namespace from a JSON array, with optional metadata and expiration settings for each pair. Existing values and expirations are overwritten. If neither `expiration` nor `expiration_ttl` is specified, the key-value pair will not expire. If both are set, `expiration_ttl` takes precedence. The entire request must be 100 megabytes or less. The result reports the number of successful writes and any keys that failed and should be retried.

##### Security

<details>

<summary>API Token</summary>



The preferred authorization scheme for interacting with the Cloudflare API. <a href="https://developers.cloudflare.com/fundamentals/api/get-started/create-token/">Create a token</a>.

**Example:**<code>Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY</code>

</details>

<details>

<summary>API Email + API Key</summary>



The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

**Example:**<code>X-Auth-Email: user@example.com</code>

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

**Example:**<code>X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194</code>

</details>

##### Accepted Permissions (at least one required)

`Workers KV Storage Write`

##### ParametersExpand Collapse

namespaceID string

ID of the Workers KV namespace.

maxLength32

[Link to this property](<#(resource)%20kv.namespaces%20%3E%20(method)%20bulk_update%20%3E%20(params)%20default%20%3E%20(param)%20namespace_id%20%3E%20(schema)>)

<details>

<summary>

params NamespaceBulkUpdateParams

</summary>

AccountID param.Field\[string]

Path param: ID of the Cloudflare account that owns the Workers KV namespaces.

maxLength32

<a href="#(resource)%20kv.namespaces%20%3E%20(method)%20bulk_update%20%3E%20(params)%20default%20%3E%20(param)%20account_id">Link to this property</a>

<details>

<summary>

Body param.Field\[\[]NamespaceBulkUpdateParamsBody]

Body param

</summary>

Key string

A key’s name. The name may be at most 512 bytes. All printable, non-whitespace characters are valid.

maxLength512

<a href="#(resource)%20kv.namespaces%20%3E%20(method)%20bulk_update%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20key">Link to this property</a>

Value string

A UTF-8 encoded string to be stored, up to 25 MiB in length.

maxLength26214400

<a href="#(resource)%20kv.namespaces%20%3E%20(method)%20bulk_update%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20value">Link to this property</a>

Base64 boolOptional

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.

<a href="#(resource)%20kv.namespaces%20%3E%20(method)%20bulk_update%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20base64">Link to this property</a>

Expiration float64Optional

Expires the key at a certain time, measured in number of seconds since the UNIX epoch.

<a href="#(resource)%20kv.namespaces%20%3E%20(method)%20bulk_update%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20expiration">Link to this property</a>

ExpirationTTL float64Optional

Number of seconds until the key expires. Must be at least 60. Takes precedence over <code>expiration</code> when both are specified.

minimum60

<a href="#(resource)%20kv.namespaces%20%3E%20(method)%20bulk_update%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20expiration_ttl">Link to this property</a>

Metadata unknownOptional

Arbitrary JSON that is associated with a key.

<a href="#(resource)%20kv.namespaces%20%3E%20(method)%20bulk_update%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20metadata">Link to this property</a>

</details>

<a href="#(resource)%20kv.namespaces%20%3E%20(method)%20bulk_update%20%3E%20(params)%20default%20%3E%20(param)%20body">Link to this property</a>

</details>

[Link to this property](<#(resource)%20kv.namespaces%20%3E%20(method)%20bulk_update%20%3E%20(params)%20default>)

##### ReturnsExpand Collapse

<details>

<summary>

type NamespaceBulkUpdateResponse struct{…}

</summary>

SuccessfulKeyCount float64Optional

Number of keys successfully written or deleted by the bulk operation.

<a href="#(resource)%20kv.namespaces%20%3E%20(model)%20NamespaceBulkUpdateResponse%20%3E%20(schema)%20%3E%20(property)%20successful_key_count">Link to this property</a>

UnsuccessfulKeys \[]stringOptional

Names of keys that failed to be written or deleted. Retry the operation for these keys.

<a href="#(resource)%20kv.namespaces%20%3E%20(model)%20NamespaceBulkUpdateResponse%20%3E%20(schema)%20%3E%20(property)%20unsuccessful_keys">Link to this property</a>

</details>

[Link to this property](<#(resource)%20kv.namespaces%20%3E%20(model)%20NamespaceBulkUpdateResponse%20%3E%20(schema)>)

### Write multiple key-value pairs

Go

HTTPTypeScriptPythonGoTerraform

```
package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/kv"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  response, err := client.KV.Namespaces.BulkUpdate(
    context.TODO(),
    "0f2ac74b498b48028cb68387c421e279",
    kv.NamespaceBulkUpdateParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
      Body: []kv.NamespaceBulkUpdateParamsBody{kv.NamespaceBulkUpdateParamsBody{
        Key: cloudflare.F("My-Key"),
        Value: cloudflare.F("Some string"),
      }},
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response.SuccessfulKeyCount)
}
```

200 example

```
{
  "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"
    ]
  }
}
```

##### Returns Examples

200 example

```
{
  "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"
    ]
  }
}
```