Connect a custom-built website (Next.js, Express, Laravel, FastAPI...) to Wriai with a REST endpoint or an HMAC-SHA256 signed webhook. Includes sample payloads and copy-ready code.
Connect your proprietary website or custom backend to Wriai with just 2 lightweight REST endpoints.
“Posts on website” reads every published post on your site (including those not written with Wriai), checks keywords against Google Search Console, then fixes the SEO title, meta description and focus keyword or rewrites the whole post. Existing Custom API connections keep publishing as before; add the points below so Wriai can read everything and write to existing posts.
Add meta_title and meta_description (required), plus focus_keyword and category (recommended). Return an empty string "" when a post has none; don't omit the field. Without meta, Wriai still analyses posts but won't write, so your current meta is never erased.
Wriai reads 50 posts at a time (limit=50), page=1, 2, 3... up to 1,000 posts. Page 2 must return the next 50 posts, not page 1 again. Newest first.
The Posts on website sync always sends contentHtml=true. When only SEO fields change, Wriai sends this content back unchanged, so it must be the post's complete HTML (not truncated). Without HTML, Wriai scores the public page but won't write.
When post_id is set, return only that post. Wriai uses it to read a post before and after an update. Without it Wriai scans page by page (slower).
Find the post by article.post_id, save title, slug, content_html, meta_title, meta_description, focus_keyword, category when present in the payload (empty strings included), and keep fields that are not sent. If the post doesn't exist return 404, not 200. Wriai reads the post back after writing: a 200 that saved nothing is reported as an error.
If you allow slug changes, redirect the old URL to the new one (301) so rankings carry over.
// GET {Endpoint URL}?limit=50&page=2&contentHtml=true
// GET {Endpoint URL}?limit=50&page=1&contentHtml=true&post_id=123 (chỉ trả bài 123)
[
{
"id": "123",
"title": "Hướng dẫn tối ưu SEO cho website Next.js",
"slug": "huong-dan-toi-uu-seo-nextjs",
"url": "https://your-site.com/blog/huong-dan-toi-uu-seo-nextjs",
"date": "2026-10-10T08:00:00Z",
"modified": "2026-10-12T09:30:00Z",
"contentHtml": "<h2>...</h2><p>...</p>", // đủ HTML khi contentHtml=true
// MỚI: bắt buộc để Wriai ghi được SEO ("" nếu bài chưa đặt)
"meta_title": "Tối ưu SEO Next.js: hướng dẫn từ A-Z",
"meta_description": "Cách tối ưu SEO cho website Next.js ...",
// MỚI: nên có
"focus_keyword": "tối ưu seo nextjs",
"category": "kien-thuc-seo"
}
]// app/api/articles/route.ts (hoặc nhánh posts.get / article.update trong webhook)
export async function GET(req: Request) {
// ...kiểm tra Authorization như cũ
const sp = new URL(req.url).searchParams;
const limit = Math.min(Number(sp.get("limit") || 50), 100);
const page = Math.max(1, Number(sp.get("page") || 1));
const postId = sp.get("post_id");
const withContent = sp.get("contentHtml") === "true";
const posts = await db.post.findMany({
where: { status: "published", ...(postId ? { id: postId } : {}) },
orderBy: { publishedAt: "desc" },
skip: postId ? 0 : (page - 1) * limit, // tôn trọng page
take: postId ? 1 : limit, // tôn trọng limit
});
return Response.json(posts.map((p) => ({
id: String(p.id), title: p.title, slug: p.slug, url: `https://your-site.com/blog/${p.slug}`,
date: p.publishedAt, modified: p.updatedAt,
...(withContent ? { contentHtml: p.contentHtml } : {}),
meta_title: p.metaTitle ?? "",
meta_description: p.metaDescription ?? "",
focus_keyword: p.focusKeyword ?? "",
category: p.categorySlug ?? "",
})));
}
// event === "article.update": chỉ ghi trường CÓ trong payload, trường vắng thì giữ nguyên
const a = payload.article;
const post = await db.post.findUnique({ where: { id: a.post_id } });
if (!post) return Response.json({ error: "Post not found" }, { status: 404 }); // không trả 200
const data: Record<string, unknown> = {};
if ("title" in a) data.title = a.title;
if ("slug" in a) data.slug = a.slug;
if ("content_html" in a) data.contentHtml = a.content_html;
if ("meta_title" in a) data.metaTitle = a.meta_title;
if ("meta_description" in a) data.metaDescription = a.meta_description;
if ("focus_keyword" in a) data.focusKeyword = a.focus_keyword;
if ("category" in a) data.categorySlug = a.category;
await db.post.update({ where: { id: post.id }, data });
return Response.json({ success: true, post_id: String(post.id), url: `https://your-site.com/blog/${data.slug ?? post.slug}` });Check: go to Articles → “Posts on website” → Sync from website. Open a post: if the “posts.get does not return meta_title…” note is gone, your site is ready for Wriai to update.
Choose the integration method that fits best with your website backend
Authorization: Bearer YOUR_KEY(YOUR_KEY: The secret token you configure in your Website Settings on Wriai)
limit: Max posts to return (default 100; Posts on website sends 50).page: Page number (default 1). Page 2 must return the next posts.post_id: Optional. When set, return only that post.contentHtml (true / false): Default is false. When false, backend only returns id, title, url, date (ultra-lightweight < 100KB for 1,000 posts). Wriai requests contentHtml=true for 2-way internal linking and for the “Posts on website” sync (50 posts per page): return the full post HTML then.Wriai calls this endpoint to retrieve published articles for “Posts on website” (optimising existing posts), Content Decay analysis and automated 2-way internal link building.
Your backend should always enforce a default LIMIT (max 50 - 100 latest posts, ORDER BY date DESC) to avoid OOM or HTTP 504 timeouts when a site has thousands of posts.
[
{
"id": "1",
"title": "Tiêu đề bài viết",
"url": "https://your-site.com/bai-viet-1",
"slug": "bai-viet-1",
"date": "2026-03-20T10:00:00Z",
"contentHtml": "", // Chỉ cần trả về khi query có contentHtml=true
// Cho "Bài trên website" ("" nếu chưa đặt):
"meta_title": "SEO title của bài",
"meta_description": "Meta description của bài",
"focus_keyword": "từ khoá chính",
"category": "chuyen-muc"
}
]⚡ Performance Tip: When contentHtml=false, 1,000+ posts will be under 100KB and load in 50ms! Content Decay and 1-Click Refresh work 100% seamlessly.
Authorization: Bearer YOUR_KEY(YOUR_KEY: The secret token you configure in your Website Settings on Wriai)
{ "event": "...", "article": { ... } }ping: connection test, return 200.article.publish: create a post, return post_id and url.article.update: overwrite the post by article.post_id (1-Click AI Refresh, link injection).article.delete: trash or delete the post.Wriai POSTs to the exact Endpoint URL from Website Settings (the same URL as GET). If the URL contains :id or {id}, Wriai substitutes the post_id on updates.
{
"success": true,
"post_id": "123",
"url": "https://your-site.com/bai-viet-1"
}* For article.update, if your server returns 404/405 to POST, Wriai retries with PUT.
Applies to both approaches. Every write is an HTTP POST to the exact Endpoint URL configured in Website Settings, distinguished by the event field in the body. If the Endpoint URL contains :id or {id}, Wriai substitutes the post_id when updating.
| Operation | When | HTTP | event |
|---|---|---|---|
| Connection test | Clicking Test Connection in Website Settings | POST | ping |
| Publish new article | Publish button / scheduled autopilot | POST | article.publish |
| Update article | 1-Click AI Refresh, internal link injection, content sync | POST (retries PUT on 404/405) | article.update |
| Delete article | Deleting in Wriai (action: trash | force_delete) | POST | article.delete |
| List articles | Posts on website, Content Decay, internal linking | GET ?limit&page&contentHtml&post_id (POST on 404/405) | posts.get |
| Fetch categories | Category sync | POST | categories.get |
| Fetch authors | E-E-A-T author selection | POST | authors.get |
| Content-Type | application/json | Body is always JSON (UTF-8). |
| User-Agent | Wriai-Content-Bot/2026.1 | Use it to allowlist Wriai on your firewall / Cloudflare. |
| X-Wriai-Event | article.publish | Same value as the event field in the body. |
| X-Wriai-Timestamp | 1791622800000 | Unix timestamp (ms) as a string. |
| X-Wriai-Signature | sha256=<hex> | HMAC-SHA256 of the raw body, keyed with the site's API Key / Secret Token. |
| Authorization | Bearer <API Key> | Sent for Bearer-style auth (Approach 1). |
| X-API-Key | <API Key> | Same key, for backends expecting an API key header. |
{
"event": "article.publish",
"action": "create",
"timestamp": "2026-10-10T08:00:00.000Z",
"site_id": "cmsite123abc",
"site_domain": "your-site.com",
"article": {
"id": "cmart456def",
"site_id": "cmsite123abc",
"title": "Hướng dẫn tối ưu SEO cho website Next.js",
"slug": "huong-dan-toi-uu-seo-nextjs",
"content_html": "<h2>Giới thiệu</h2><p>...</p>",
"content_markdown": "## Giới thiệu\n\n...",
"meta_title": "Hướng dẫn tối ưu SEO cho website Next.js",
"meta_description": "Các bước tối ưu SEO kỹ thuật cho Next.js App Router...",
"focus_keyword": "tối ưu seo nextjs",
"secondary_keywords": ["seo nextjs", "next.js app router seo"],
"category": "seo",
"status": "publish",
"reading_time": 8,
"word_count": 1750,
"featured_image": {
"url": "https://cdn.yupvox.com/images/abc.webp",
"alt": "Hướng dẫn tối ưu SEO cho website Next.js",
"title": "Hướng dẫn tối ưu SEO cho website Next.js"
},
"images": [
{ "url": "https://cdn.yupvox.com/images/def.webp", "alt": "...", "title": "...", "placement": "inline" }
],
"author": {
"name": "Nguyễn Văn A",
"title": "SEO Lead",
"bio": "...",
"socialLinks": "https://linkedin.com/in/..."
},
"faq_schema": [
{ "question": "Next.js có tốt cho SEO không?", "answer": "..." }
]
}
}| event | string | Event name. Route on this field (not on action). |
| action | string | "create" on publish, "update" on update, "trash" | "force_delete" on delete, "test" on ping. |
| article.id | string | Wriai's article ID (on article.publish). Use it to de-duplicate retries. |
| article.post_id | string | The post ID on your site (on update / delete) — the post_id you returned when publishing. |
| article.slug | string | SEO slug, ASCII only. May be empty: generate one from title. |
| article.content_html | string | Final HTML (images, tables, internal links included). Store as-is. |
| article.content_markdown | string | Source Markdown, if your CMS stores Markdown. |
| article.meta_title / meta_description | string | <title> and meta description. |
| article.focus_keyword / secondary_keywords | string / string[] | Primary and secondary keywords. |
| article.category | string | Category slug (from categories.get), defaults to "general". |
| article.status | string | "publish" or "draft". |
| article.featured_image | object | null | { url, alt, title } — hosted on Wriai's CDN; hotlink or download it. |
| article.images | array | In-article images: { url, alt, title, placement }. |
| article.author | object | null | { name, title, bio, socialLinks } — E-E-A-T author. |
| article.faq_schema | array | [{ question, answer }] taken from the FAQ section already in content. Use it only for FAQPage JSON-LD; do not render it again as HTML (it would duplicate). Empty when the article has no FAQ. |
| article.reading_time / word_count | number | Reading time (minutes) and word count. |
HTTP/1.1 200 OK
Content-Type: application/json
{
"success": true,
"post_id": "123",
"url": "https://your-site.com/blog/huong-dan-toi-uu-seo-nextjs"
}url: the post's public URL. Used for display, Google Indexing and internal links. If missing, Wriai falls back to https://domain/slug.post_id: the post's ID on your site. Required for 1-Click Refresh, link injection and deletes from Wriai.post_url, link, id, postId, or nested under post / data.HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json
{
"success": false,
"error": "Slug đã tồn tại"
}error message. Wriai shows it to the user.{ "success": true } instead of 404/501 so other features keep working.| Symptom | Cause | Fix |
|---|---|---|
| Test Connection passes but publishing fails / HTTP 501 | The test only sends a ping event. Your backend has no branch for event "article.publish" (often compared against "article.published", or routed on the action field). | Match event === "article.publish" exactly. For unknown events return 200 { success: true }, not 501. |
| HTTP 401 / 403 | The key on your site differs from the API Key / Secret Token in Wriai, or the signature is computed on re-serialized JSON. | Compute the HMAC on the raw body (req.text(), express.raw, php://input) before JSON.parse. |
| HTTP 404 / 405 | The route does not allow the method, or the Endpoint URL in Wriai points elsewhere. | Allow GET and POST (PUT recommended) on the exact Endpoint URL configured in Website Settings. |
| Timeout while publishing | Your backend takes longer than 30 seconds (e.g. downloading all images synchronously). | Save the post and respond immediately; move image downloads / page builds to a background job. |
| Wrong article link shown in Wriai | The response has no url, so Wriai falls back to https://domain/slug. | Return the full URL of the published post. |
| Cannot update / delete a published post | The article.publish response had no post_id, so Wriai doesn't know the post's ID on your site. | Always return post_id; look posts up by article.post_id on article.update / article.delete. |
| Blocked by Cloudflare / WAF (HTTP 403 HTML page) | Bot protection, or body size limits (long articles can be several hundred KB). | Allowlist the Wriai-Content-Bot User-Agent and raise the body limit to at least 5 MB. |
The YOUR_KEY (or Secret Token / Bearer Token) in all code snippets is a private secret string defined by you (e.g. my_secret_token_2026) and entered into the "API Key / Secret Token" field in Website Settings on Wriai (under: Dashboard → Websites → Edit Website):
When Wriai calls your API (GET posts or POST/PUT reverse links), Wriai automatically sends 'Authorization: Bearer <Key configured in your Site>'. Your backend verifies this bearer token.
Wriai uses this key as the HMAC-SHA256 secret for 'x-wriai-signature'. Your backend validates this signature using the same key.
HTTP 405 occurs when Wriai sends a request to your Endpoint URL, but your backend or web server router disallows that HTTP method:
Ensure your server allows methods GET, POST, PUT, OPTIONS and headers Authorization, Content-Type, X-Wriai-Signature.
Always respond with JSON, never HTML or redirects. Success: HTTP 200 with { success: true, post_id, url }. Failure: HTTP 4xx with { success: false, error }.