Example code
End-to-end examples in curl, Node.js, and Python: upload an image, upsert a post, and publish it.
The full flow, "upload an image → create the post (upsert) → publish if it's a draft", in each language. These examples assume your key is stored in the environment variable WEEKERP_API_KEY.
curl
BASE=https://api-open.weekerp.com/blog/v1
AUTH="Authorization: Bearer $WEEKERP_API_KEY"
# 1) Image
COVER=$(curl -s -X POST "$BASE/uploads" -H "$AUTH" -F "file=@cover.png" | jq -r .url)
# 2) Post (update if it exists, create if not)
POST_ID=$(curl -s -X PUT "$BASE/posts/external/prod-123" -H "$AUTH" \
-H "Content-Type: application/json" \
-d "{\"lang\":\"en\",\"slug\":\"product-123-review\",\"title\":\"Product 123 review\",
\"thumbnail\":\"$COVER\",\"content\":\"# Product 123\\n\\n\"}" | jq -r .id)
# 3) Publish
curl -s -X POST "$BASE/posts/$POST_ID/publish" -H "$AUTH" | jq .status
Node.js (18 or later, fetch)
import { readFile } from 'node:fs/promises';
const BASE = 'https://api-open.weekerp.com/blog/v1';
const headers = { Authorization: `Bearer ${process.env.WEEKERP_API_KEY}` };
async function call(method, path, body) {
const res = await fetch(`${BASE}${path}`, {
method,
headers: body instanceof FormData ? headers : { ...headers, 'Content-Type': 'application/json' },
body: body === undefined || body instanceof FormData ? body : JSON.stringify(body),
});
if (res.status === 204) return null;
const data = await res.json();
if (!res.ok) {
// Branch on code, not message
const err = new Error(`${data.error.code}: ${data.error.message}`);
err.code = data.error.code;
err.retryAfter = Number(res.headers.get('Retry-After')) || undefined;
throw err;
}
return { status: res.status, data };
}
// 1) Image
const form = new FormData();
form.append('file', new Blob([await readFile('cover.png')], { type: 'image/png' }), 'cover.png');
const { data: cover } = await call('POST', '/uploads', form);
// 2) Post (upsert)
const { status, data: post } = await call('PUT', '/posts/external/prod-123', {
lang: 'en',
slug: 'product-123-review',
title: 'Product 123 review',
thumbnail: cover.url,
content: `# Product 123\n\n`,
categories: ['review'],
});
console.log(status === 201 ? 'created' : 'updated', post.id);
// 3) Publish only if it's a draft
if (post.status === 'draft') {
const { data: published } = await call('POST', `/posts/${post.id}/publish`);
console.log(published.status); // "published"
}
Python (requests)
import os
import time
import requests
BASE = "https://api-open.weekerp.com/blog/v1"
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['WEEKERP_API_KEY']}"
def call(method, path, **kwargs):
for _ in range(3):
res = session.request(method, BASE + path, timeout=60, **kwargs)
if res.status_code == 429:
# Over the limit: wait as long as the server says, then retry
time.sleep(int(res.headers.get("Retry-After", "1")))
continue
if res.status_code == 204:
return res.status_code, None
body = res.json()
if not res.ok:
raise RuntimeError(f"{body['error']['code']}: {body['error']['message']}")
return res.status_code, body
raise RuntimeError("rate_limited: too many retries")
# 1) Image
with open("cover.png", "rb") as f:
_, cover = call("POST", "/uploads", files={"file": ("cover.png", f, "image/png")})
# 2) Post (upsert)
status, post = call("PUT", "/posts/external/prod-123", json={
"lang": "en",
"slug": "product-123-review",
"title": "Product 123 review",
"thumbnail": cover["url"],
"content": f"# Product 123\n\n",
"categories": ["review"],
})
print("created" if status == 201 else "updated", post["id"])
# 3) Publish only if it's a draft
if post["status"] == "draft":
_, published = call("POST", f"/posts/{post['id']}/publish")
print(published["status"]) # "published"
Automation tools and AI agents
- n8n, Zapier, Make: call the paths above from an HTTP Request node and add the header
Authorization: Bearer <key>. If the same item can run more than once, usePUT /posts/external/{ID}. It never creates the same post twice. - AI agents: we recommend giving the agent a Write only key so it creates drafts only, and having someone on your team review and publish them in the blog dashboard. Tell the agent to write content in Markdown and wrap code examples in ```.