cloudflare-go icon indicating copy to clipboard operation
cloudflare-go copied to clipboard

KV stores value as a json

Open aliforever opened this issue 1 year ago • 3 comments

Confirm this is not a feature request

  • [x] This is a bug

Confirm this is a Go library issue and not an underlying Cloudflare API issue

  • [x] This is an issue with the Go library

Describe the bug

Using client.KV.Namespaces.Values.Update stores KV value as {"value": "...."}.

Image

type NamespaceValueUpdateParams struct {
	// Identifier
	AccountID param.Field[string] `path:"account_id,required"`
	// Arbitrary JSON to be associated with a key/value pair.
	Metadata param.Field[string] `json:"metadata,required"`
	// A byte sequence to be stored, up to 25 MiB in length.
	Value param.Field[string] `json:"value,required"`
	// The time, measured in number of seconds since the UNIX epoch, at which the key
	// should expire.
	Expiration param.Field[float64] `query:"expiration"`
	// The number of seconds for which the key should be visible before it expires. At
	// least 60.
	ExpirationTTL param.Field[float64] `query:"expiration_ttl"`
}

To Reproduce

_, err = client.KV.Namespaces.Values.Update(
			context.Background(),
			{namespaceid},
			{keyid},
			kv.NamespaceValueUpdateParams{
				AccountID:  cloudflare.F({account_id}),
				Value:      cloudflare.F({value}),
				Expiration: cloudflare.F(float64({expiry})),
			},
		)

Code snippets


OS

Windows

Go version

Go 1.23

Library version

github.com/cloudflare/cloudflare-go/[email protected]

aliforever avatar Feb 10 '25 11:02 aliforever

Can confirm that also hit this and feels very wonky

karalabe avatar Mar 03 '25 12:03 karalabe

The example on the Cloudflare API page is also borken, it will error with:

can not parse value and metadata from multipart request body: 'could not parse multipart request: 'no multipart boundary param in Content-Type''

karalabe avatar Mar 03 '25 12:03 karalabe

@aliforever You can ram through your request by working around the encoder which dishonours the API and call it properly directly:

client.KV.Namespaces.Values.Update(context.Background(), "your-namespace",
	"key", kv.NamespaceValueUpdateParams{AccountID: "yout-account-id"},
	option.WithRequestBody("*/*", []byte("test")))

karalabe avatar Mar 03 '25 12:03 karalabe

This issue hasn't been updated in a while. If it's still reproducing, please comment to let us know. Thank you!

github-actions[bot] avatar May 02 '25 16:05 github-actions[bot]