ReferencePremium
CoullWorks Blog for Laravel API reference
The JSON:API read routes and the optional write routes for posts, categories, tags, authors and images, with authentication, errors and examples.
Updated 16 November 2026Back to the package pageBuy
The API module is a typed JSON:API for single-page and headless front ends. Reads are on by default and live under the prefix api/blog/v1 (coullworks-blog.api.prefix). The admin write routes are off until you switch them on. They call the same actions as the admin screens and fire the same events, so a listener cannot tell an API write from an admin write.
Switch on the write routes#
'api' => [
'write' => [
'enabled' => true,
// What your application puts in front of every write route: the guard that reads your token.
'middleware' => ['auth:sanctum'],
],
'rate_limit' => ['write' => 30],
],The package requires no auth package. middleware defaults to ['auth'], which authenticates through your default guard. Routes are not registered while enabled is false, and a cached route file must be rebuilt after the switch.
Authentication#
- Your middleware authenticates the request (401 when it cannot).
- The request must carry an
Authorizationheader. A browser session with noAuthorizationheader is refused with 401, because these routes are stateless and have no CSRF protection. - The user must hold the ability for the route (403 otherwise).
| Route | Ability |
|---|---|
POST /posts | blog.posts.create |
PATCH /posts/{id} | blog.posts.update. A status of published, scheduled or archived, and featured, also need blog.posts.publish |
DELETE /posts/{id} | blog.posts.delete |
| Categories | blog.categories.manage |
| Tags | blog.tags.manage |
| Authors | blog.authors.manage |
POST /media | blog.posts.create or blog.posts.update |
Not exposed: blogs, settings, the licence, redirects, comments, AI and import.
Requests#
Every route exists in two forms: api/blog/v1/posts (the blog comes from your BlogResolver) and api/blog/v1/blogs/{blog}/posts. A body must be sent as Content-Type: application/vnd.api+json (415 otherwise) and be a JSON:API document, {"data": {"type": "posts", "attributes": {...}, "relationships": {...}}}.
Posts#
Attributes: locale, title, slug, excerpt, blocks (a list of {type, v, data}), meta_title, meta_description, robots, canonical_url, ai_disclosure, featured_image ({disk, path, alt, width, height, mime}, null clears it). On PATCH also status (draft, scheduled, published, archived), scheduled_at and featured.
Relationships: categories, tags, authors, each {"data": [{"type": "categories", "id": "3"}]}. For categories and authors, "meta": {"primary": true} on one identifier marks the primary. A relationship left out is left alone; an empty list clears it.
POSTcreates a draft with its first translation inlocaleand answers 201 with aLocationheader.status,scheduled_atandfeaturedare refused on create (422): create the draft, then PATCH it.PATCHchanges the translation named bylocale, or adds it when the post has none in that locale. Other translations are unchanged.DELETEanswers 204. A published post leaves a 410 for its addresses.
Categories, tags and authors#
- Category:
locale,name,slug,description,meta_title,meta_description,robots,is_active,list_mode,posts_per_page,include_in_menu, and theparentrelationship. A parent that would make a loop is 422. Deleting a category with children is 409. - Tag:
locale,name,slug,description,meta_title,meta_description,robots,is_active. - Author:
name,slug,job_title,bio,email,is_active,links.DELETE /authors/{id}?replacement={id}hands the author's posts to the replacement; an author with posts and no replacement is 409.
A taken category or tag slug is 422. A taken post slug is not an error: the post gets the next free one (taken-2).
Media#
POST /media with a multipart field file answers 201 with {"disk", "path", "url", "width", "height", "mime"}. Use disk and path as a block's media or a post's featured_image. A non-image or too large file is 422.
Responses#
| Status | When |
|---|---|
| 401 | No credential, no Authorization header, or a cookie-only session |
| 403 | The user lacks the ability |
| 404 | The resource is not in this blog, or the licence gate refuses the host |
| 409 | The id in the document differs from the address, a refused status move, an author with posts and no replacement, a category with children, or a listener vetoed the change |
| 415 | The body is not application/vnd.api+json |
| 422 | The document is invalid. One error object per problem, each with source.pointer |
| 429 | Over the rate limit. Retry-After says when to try again |
Writes run in one transaction and store nothing when any part is refused. The limiter blog-api-write allows api.rate_limit.write requests a minute (30 by default) per authenticated user, or per IP when there is none. It needs a cache store that supports atomic increments.
Example#
curl -X POST https://example.com/api/blog/v1/posts \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/vnd.api+json" \
-H "Accept: application/vnd.api+json" \
-d '{"data":{"type":"posts","attributes":{"title":"Hello","blocks":[{"type":"coullworks.text","v":1,"data":{"body":"<p>First paragraph.</p>"}}]}}}'Then publish it with a PATCH:
curl -X PATCH https://example.com/api/blog/v1/posts/12 \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/vnd.api+json" \
-d '{"data":{"type":"posts","id":"12","attributes":{"status":"published"}}}'






