Setup

To use the Posts API, install the @wix/blog package using npm or Yarn:

Copy
1
npm install @wix/blog

or

Copy
1
yarn add @wix/blog

Then import { posts } from @wix/blog:

Copy
1
import { posts } from '@wix/blog'
Was this helpful?
Yes
No

getPost( )

Gets a post by the specified ID.

The getPost() function returns a Promise that resolves to a post whose ID matches the given ID.

Permission Scopes

For app development, you must have one of the following permission scopes:
Read Blog
Manage Blog
Read Draft Blog Posts
Learn more about permission scopes.
Copy
function getPost(postId: string, options: GetPostOptions): Promise<GetPostResponse>
Method Parameters
postIdstringRequired

Post ID.


optionsGetPostOptions

Options specifying which fields to return.

Returns
Return Type:Promise<GetPostResponse>
Was this helpful?
Yes
No

getPostBySlug( )

Gets a post by the provided slug.

The getPostBySlug() function returns a Promise that resolves to a post whose slug matches the given slug.

The slug is the end of a post's URL that refers to a specific post. For example, if a post's URL is https:/example.com/blog/post/my-post-slug, the slug is my-post-slug. The slug is case-sensitive, and is generally derived from the post title, unless specified otherwise.

Permission Scopes

For app development, you must have one of the following permission scopes:
Read Blog
Manage Blog
Read Draft Blog Posts
Learn more about permission scopes.
Copy
function getPostBySlug(slug: string, options: GetPostBySlugOptions): Promise<GetPostBySlugResponse>
Method Parameters
slugstringRequired

Slug of the post to retrieve.

The end of a post's URL, for example, https:/example.com/blog/post/my-post-slug. Case sensitive and generally based on the post title if not specified.


optionsGetPostBySlugOptions

Options specifying which fields to return.

Returns
Return Type:Promise<GetPostBySlugResponse>
Was this helpful?
Yes
No

getPostMetrics( )

Gets a specified post's metrics.

The getPostMetrics() function returns a Promise that resolves to the specified post's metrics.

A post's metrics include the comments, likes, and views the post receives.

Permission Scopes

For app development, you must have one of the following permission scopes:
Read Blog
Manage Blog
Read Draft Blog Posts
Learn more about permission scopes.
Copy
function getPostMetrics(postId: string): Promise<GetPostMetricsResponse>
Method Parameters
postIdstringRequired

Post ID.

Returns
Return Type:Promise<GetPostMetricsResponse>
Was this helpful?
Yes
No

getTotalPosts( )

Gets the total amount of published posts on the blog.

The getTotalPosts() function returns a Promise that resolves to the total amount of published posts on your blog's site.

You can use the language option to filter posts for a specified language.

Permission Scopes

For app development, you must have one of the following permission scopes:
Read Blog
Manage Blog
Read Draft Blog Posts
Learn more about permission scopes.
Copy
function getTotalPosts(options: GetTotalPostsOptions): Promise<GetTotalPostsResponse>
Method Parameters
optionsGetTotalPostsOptions

Language Options.

Returns
Return Type:Promise<GetTotalPostsResponse>
Was this helpful?
Yes
No

listPosts( )

Retrieves a list of published posts.

The listPosts() function returns a Promise that resolves to a list of up to 100 published posts.

Using the options parameter, you can filter your list of posts, set the amount of posts to be returned, and sort your list in a specified order.

By default, the list is sorted by firstPublishedDate in descending order, and the amount of posts returned is 50.

Permission Scopes

For app development, you must have one of the following permission scopes:
Read Blog
Manage Blog
Read Draft Blog Posts
Learn more about permission scopes.
Copy
function listPosts(options: ListPostsOptions): Promise<ListPostsResponse>
Method Parameters
optionsListPostsOptions

Sort, filter, and paging options.

Returns
Return Type:Promise<ListPostsResponse>
Was this helpful?
Yes
No

queryPostCountStats( )

Retrieves the number of published posts per month within a specified time range.

The queryPostCountStats() function returns a Promise that resolves to the number of posts per month within the specified time range.

You can set the time range using the rangeStart and months properties. The time range always starts on the 1st day of the month set in rangeStart and includes the number of months following rangeStart. For example, if rangeStart is set to '2022-03-13' and months is set to 4, the time range will be from '2022-03-01' until '2022-06-30'. The time range ends on the last day of the month.

Note: If there are no published posts in a specific month, that month is not included in the response. For example, let's say a blog has 0 posts dated in February 2022. If rangeStart is set to '2022-01-01' and months is set to 3, the response includes postCount values for January and March, but not February.

Permission Scopes

For app development, you must have one of the following permission scopes:
Read Blog
Manage Blog
Read Draft Blog Posts
Learn more about permission scopes.
Copy
function queryPostCountStats(options: QueryPostCountStatsOptions): Promise<QueryPostCountStatsResponse>
Method Parameters
optionsQueryPostCountStatsOptions

Options specifying time frame, sort, and filter.

Returns
Return Type:Promise<QueryPostCountStatsResponse>
Was this helpful?
Yes
No

queryPosts( )

Creates a query to retrieve a list of posts.

The queryPosts() function builds a query to retrieve a list of up to 100 posts, and returns a PostsQueryBuilder object.

The returned object contains the query definition which is typically used to run the query using the find() function.

You can refine the query by chaining PostsQueryBuilder functions onto the query. PostsQueryBuilder functions enable you to sort, filter, and control the results that queryPosts() returns.

queryPosts() runs with these PostsQueryBuilder defaults that can be overridden:

Note that the default limit is '50', but the max limit is '100'.

To learn how to query posts, refer to the table below.

The following PostsQueryBuilder functions are supported for the queryPosts() function. For a full description of the Posts object, see the object returned for the items property in PostsQueryResult.

PROPERTYSUPPORTED FILTERS & SORTING
_ideq(),ne(),hasSome(),ascending(),descending()
titleeq(),ne(),startsWith(),hasSome(),exists(),in(),ascending(),descending()
firstPublishedDateeq(),ne(),lt(),le(),gt(),ge(),in(),ascending(),descending()
lastPublishedDateeq(),ne(),lt(),le(),gt(),ge(),in(),ascending(),descending()
slugeq(),ne(),hasSome(),ascending(),descending()
featuredeq(),ne(),ascending(),descending()
pinnedeq(),ne(),ascending(),descending()
categoryIdshasSome(),hasAll()
coverMedia.enabledeq(),ne()
memberIdeq(),ne(),hasSome()
hashtagshasSome(),hasAll()
commentingEnabledeq(),ne(),ascending(),descending()
minutesToReadeq(),ne(),lt(),le(),gt(),ge(),in()
tagIdshasSome(),hasAll()
pricingPlanIdshasSome(),hasAll()
translationIdeq(),ne(),exists(),in()
languageeq(),ne(),hasSome(),exists(),in()
metrics.commentseq(),ne(),lt(),le(),gt(),ge(),in(),ascending(),descending()
metrics.likeseq(),ne(),lt(),le(),gt(),ge(),in(),ascending(),descending()
metrics.viewseq(),ne(),lt(),le(),gt(),ge(),in(),ascending(),descending()

Permission Scopes

For app development, you must have one of the following permission scopes:
Read Blog
Manage Blog
Read Draft Blog Posts
Learn more about permission scopes.
Copy
function queryPosts(options: QueryPostsOptions): PostsQueryBuilder
Method Parameters
optionsQueryPostsOptions

Options specifying which fields to return.

Returns
Return Type:PostsQueryBuilder
Was this helpful?
Yes
No