KV API giving FormData errors

I'm trying to write to KV, following the API docs here:
https://developers.cloudflare.com/api/operations/workers-kv-namespace-write-key-value-pair-with-metadata

However I continue to get this response
{
  result: null,
  success: false,
  errors: [
    {
      code: 10047,
      message: "can not parse value and metadata from multipart request body: 'error getting part of multipart request, after reading 0 parts: 'multipart: NextPart: EOF''"
    }
  ],
  messages: []
}

Here's my code with some hardcoded values for testing:
export async function kvSet(key: string, value: any, opts: { metadata?: Record<string, string> }) {
    const form = new FormData();
    form.append("metadata", "");
    form.append("value", "test");


    const options = {
        method: 'PUT',
        headers: {
            'Content-Type': 'multipart/form-data; boundary=---011000010111000001101001',
            Authorization: `Bearer ${env.KV_AUTH_TOKEN}`
        },
    };
    options.body = form
    console.log(options)


  
        const response = await fetch(`https://api.cloudflare.com/client/v4/accounts/${env.KV_ACCOUNT_ID}/storage/kv/namespaces/${env.KV_NAMESPACE_ID}/values/${key}`, options)
        const result = await response.json()
        console.log("set result", result)
        return result.result

}
Interact with Cloudflare's products and services via the Cloudflare API
Was this page helpful?