const API_TOKEN = 'YOUR_CLOUDFLARE_API_TOKEN';
const ACCOUNT_ID = 'YOUR_ACCOUNT_ID';
const NAMESPACE_ID = 'YOUR_NAMESPACE_ID';
const KV_PAIR = {
key: 'your_key',
value: 'your_value'
};
async function writeKVPair() {
const urlEscapedKey = encodeURIComponent(KV_PAIR.key);
const response = await fetch(`https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/storage/kv/namespaces/${NAMESPACE_ID}/values/${urlEscapedKey}`, {
method: 'PUT',
headers: {
'Authorization': `Bearer ${API_TOKEN}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(KV_PAIR)
});
if (response.ok) {
console.log('Key-value pair written successfully!');
} else {
console.error('Failed to write key-value pair:', await response.text());
}
}
writeKVPair();
const API_TOKEN = 'YOUR_CLOUDFLARE_API_TOKEN';
const ACCOUNT_ID = 'YOUR_ACCOUNT_ID';
const NAMESPACE_ID = 'YOUR_NAMESPACE_ID';
const KV_PAIR = {
key: 'your_key',
value: 'your_value'
};
async function writeKVPair() {
const urlEscapedKey = encodeURIComponent(KV_PAIR.key);
const response = await fetch(`https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/storage/kv/namespaces/${NAMESPACE_ID}/values/${urlEscapedKey}`, {
method: 'PUT',
headers: {
'Authorization': `Bearer ${API_TOKEN}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(KV_PAIR)
});
if (response.ok) {
console.log('Key-value pair written successfully!');
} else {
console.error('Failed to write key-value pair:', await response.text());
}
}
writeKVPair();