async function createPageWithRetry(productId: string, apiKey: string) {
const body = {
productId,
pages: [
{
slug: "docs/retry-safe-page",
title: "Retry-safe page",
content: "# Retry-safe page",
},
],
};
const key = `site-page-create-${productId}-retry-safe-page`;
for (let attempt = 0; attempt < 3; attempt += 1) {
try {
const response = await fetch("https://app.promptingco.com/api/v1/site/pages", {
method: "POST",
headers: {
"content-type": "application/json",
"x-api-key": apiKey,
"Idempotency-Key": key,
},
body: JSON.stringify(body),
});
return await response.json();
} catch (error) {
if (attempt === 2) throw error;
}
}
}