ReferencePremium
GraphQL and REST API for CoullWorks Blog for Magento 2
The cwBlogPosts query and the other GraphQL queries, the comment mutation, and the REST routes, with a response sample.
Updated 16 November 2026Back to the package pageBuy
The GraphQL and REST add-on lets a headless storefront read the blog and post comments. It is included in the price of the Blog. Reads respect what the visitor may see, so a draft, scheduled, disabled or other-store post is never returned. Install it as described on the install page.
GraphQL#
Send queries to /graphql as usual. Names are prefixed cwBlog so the add-on can sit beside another blog's schema.
| Query | Returns |
|---|---|
cwBlogPosts | A filtered, sorted, paged list of posts |
cwBlogPost(url_key, id) | One visible post |
cwBlogCategories(parent_id) | Visible categories under parent_id, or the roots, with children |
cwBlogCategory(url_key) | One category |
cwBlogTags(pageSize, currentPage) | Visible tags, paged |
cwBlogTag(url_key) | One tag |
cwBlogAuthors | Active authors, with links |
cwBlogAuthor(url_key) | One author |
cwBlogSearch(query, pageSize, currentPage) | Articles matching a query |
cwBlogComments(post_id) | Approved comments of a visible post, with parent_id for threading |
cwBlogCommentToken(post_id) | A timing token for the comment form. Not cached |
cwBlogBlockSchema | The structured block schema as JSON |
List posts#
cwBlogPosts takes a filter (category_id, tag_id, author_id, search), a sort (PUBLISHED_AT, TITLE, READING_MINUTES or CREATED_AT, with a direction), pageSize (12 by default) and currentPage. author_id cannot be combined with search. Posts with equal values in the sort field are ordered by id, so paging through a list never repeats or skips a post.
{
cwBlogPosts(
filter: { category_id: 80 }
sort: { field: PUBLISHED_AT, direction: DESC }
pageSize: 2
) {
total_count
items { id title url_key reading_minutes
author { name } categories { title } }
page_info { current_page total_pages }
}
}The response, with the first item shown:
{ "data": { "cwBlogPosts": {
"total_count": 4,
"items": [ {
"id": 952,
"title": "How to choose a three-season tent",
"url_key": "how-to-choose-a-three-season-tent",
"reading_minutes": 1,
"author": { "name": "Maya Hartley" }
} ]
} } }Posts carry everything attached#
A post has its categories, tags, author and co-authors, related posts, related products (as Magento ProductInterface), FAQs, key takeaways, meta, json_ld and hreflang. The body comes in two formats: content_html, as the storefront prints it, and content_blocks, as structured blocks described by cwBlogBlockSchema.
Post a comment#
- Query
cwBlogCommentToken(post_id: N)when the form opens. - Send
cwBlogAddCommentwith that token, an emptyhoneypotand, when reCAPTCHA is on for blog comments,captcha_response. A comment sent faster than the minimum fill time is refused, so wait at least that long. - A rate-limited request fails with a
GraphQlInputExceptionwhoseextensions.codeisRATE_LIMITED. A spam or captcha refusal returns the storefront's generic message and never says which check failed.
mutation {
cwBlogAddComment(input: {
post_id: 952
name: "Priya Nair"
content: "Thanks, this settled it."
token: "<token from cwBlogCommentToken>"
honeypot: ""
}) { status message comment_id }
}status is approved or pending, following the store's moderation settings. Send a customer token to comment as the customer.
Differences from the storefront#
- Page Builder content in
content_htmllacks thedata-decoded="true"attribute the storefront adds, and Page Builder's background image conversion is not applied. Content without Page Builder is identical. - Each query declares a cache identity using the blog's
cwb_*tags, which the Blog purges on save. Magento's built-in page cache removes theX-Magento-Tagsheader outside developer mode. Behind Varnish the tags are sent.
REST#
Reads of posts, categories, tags and authors are anonymous and show only what the reader may see. Writes, and the admin reads that include drafts, need an admin token with the matching ACL resource (CoullWorks_Blog::posts, ::categories, ::tags, ::authors).
| Method and path | Access |
|---|---|
GET /V1/cwblog/posts and /V1/cwblog/posts/:urlKey | Anonymous |
GET /V1/cwblog/categories and /V1/cwblog/categories/:urlKey | Anonymous |
GET /V1/cwblog/tags and /V1/cwblog/tags/:urlKey | Anonymous |
GET /V1/cwblog/authors and /V1/cwblog/authors/:urlKey | Anonymous |
GET /V1/cwblog/admin/{posts,categories,tags,authors} and /:id | Admin token with the ACL resource |
POST /V1/cwblog/{posts,categories,tags,authors}, PUT and DELETE on /:id | Admin token with the ACL resource |
List endpoints take Magento's searchCriteria.
Licence#
The add-on follows the Blog's licence. When the current store view's domain is not licensed, every GraphQL query and mutation answers with an authorisation error and every REST route answers 401, both with "This domain isn't licensed for CoullWorks Blog."







