Writing bulk key value pairs

I’m unable to write multiple key-value pairs via the API. Unfortunately, the documentation does not actually show multiple pairs being submitted.

Echoing out a CURL attempt with an array for bulk values, it shows spaces between each key or value:
curl -X PUT "https://api.cloudflare.com/client/v4/accounts/01a7362d577a6c3019a474fd6f485823/storage/kv/namespaces/0f2ac74b498b48028cb68387c421e279/bulk" \ -H "X-Auth-Email: [email protected]" \ -H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \ -H "Content-Type: application/json" \ --data '[{"key":"a" "b" "c","value":"1" "2" "3"}]'

I get the following error:
"code": 10012,
"message": "could not parse array of key/value objects from request body: 'unexpected EOF'"

When manually entering multiple pairs, only the last pair gets inserted into the namespace (in this example, test7 as a key and value):
curl -X PUT "https://api.cloudflare.com/client/v4/accounts/01a7362d577a6c3019a474fd6f485823/storage/kv/namespaces/0f2ac74b498b48028cb68387c421e279/bulk" \ -H "X-Auth-Email: [email protected]" \ -H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \ -H "Content-Type: application/json" \ --data '[{"key":"test5","value":"test5","key":"test6","value":"test6","key":"test7","value":"test7"}]'

Could I please get an example of bulk key-value pairs beyond the documentation? I’m hoping to have the key-value pairs read from either files or array variables.

Double check your array of json key value objects, missing some braces. Should be something like:


Thank you, John. I re-worked the array so it had a similar format and it successfully loaded into Workers KV.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.