> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# QueryPostCountStats

# Package: blog

# Namespace: BlogStatsService

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/blog/posts-stats/query-post-count.md

## Permission Scopes:
Read Blog : SCOPE.DC-BLOG.READ-BLOGS

## Introduction

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

The time range is set 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 always ends on the last day of the month.
> Note: If there are no published posts in a month within the time range, 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.

---

## REST API

### Schema

```
 Method: queryPostCountStats
 Description: Retrieves the number of published posts per month within a specified time range.  The time range is set 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 always ends on the last day of the month. > Note: If there are no published posts in a month within the time range, 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.
 URL: https://www.wixapis.com/blog/v2/stats/post/count
 Method: GET
 This method is cacheable: Responses from this method are cached for optimal performance.
 Method parameters:
   query param name: language | type: language | description: Language filter.  2-or-4-letter language code in [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) format. Pass a language to only receive the period post count for that specified language.  | validation: format LANGUAGE_TAG
   query param name: months | type: months | description: Number of months to include in response.  | validation: minimum 0
   param name: order | type: Order    
      - enum:
           UNKNOWN - 
           OLDEST - 
           NEWEST - 
   query param name: rangeStart | type: rangeStart | description: Start of time range to return, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time format.  | validation: format date-time
   query param name: timeZone | type: timeZone | description: Time zone to use when calculating the start of the month.  [UTC timezone offset](https://en.wikipedia.org/wiki/List_of_UTC_offsets) format. For example, New York time zone is `-05`.  | validation: minLength 3, maxLength 100
 Return type: QueryPostCountStatsResponse
  - name: stats | type: array<PeriodPostCount> | description: List of published post counts by month.  
     - name: periodStart | type: string | description: Start of time range in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time format.  | validation: format date-time
     - name: postCount | type: integer | description: Number of posts published during this month.  | validation: minimum 0


```

### Examples

### QueryPostCountStats
```curl
~~~cURL
curl --request GET 'https://www.wixapis.com/blog/v2/stats/post/count?rangeStart=2018-11-01T00%3A00%3A00Z&order=OLDEST&months=3&language=en' \
    --header 'Authorization: <AUTH>'
~~~
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.blog.posts.queryPostCountStats(options)
 Description: Retrieves the number of published posts per month within a specified time range.  The time range is set 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 always ends on the last day of the month. > Note: If there are no published posts in a month within the time range, 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.
 This method is cacheable: Responses from this method are cached for optimal performance.
 Method parameters:
   param name: options | type: QueryPostCountStatsOptions  none  
        - name: rangeStart | type: Date | description: Start of time range to return, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time format.  
        - name: order | type: Order | description: Order of returned results.  - `OLDEST`: posts by date in ascending order. - `NEWEST`: posts by date in descending order.  Default: `OLDEST`  
             - enum: UNKNOWN, OLDEST, NEWEST
        - name: months | type: integer | description: Number of months to include in response.  | validation: minimum 0
        - name: language | type: string | description: Language filter.  2-or-4-letter language code in [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) format. Pass a language to only receive the period post count for that specified language.  | validation: format LANGUAGE_TAG
        - name: timeZone | type: string | description: Time zone to use when calculating the start of the month.  [UTC timezone offset](https://en.wikipedia.org/wiki/List_of_UTC_offsets) format. For example, New York time zone is `-05`.  | validation: minLength 3, maxLength 100
 Return type: PROMISE<QueryPostCountStatsResponse>
  - name: stats | type: array<PeriodPostCount> | description: List of published post counts by month.  
     - name: periodStart | type: Date | description: Start of time range in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time format.  
     - name: postCount | type: integer | description: Number of posts published during this month.  | validation: minimum 0


```

### Examples

### Get post count per month within a given time period
This example uses `queryPostCountStats()` to retrieve the `postCount` of published posts per month within a given time frame.

```javascript
import { posts } from '@wix/blog';

/* Sample options value:
 * {
 *   rangeStart: new Date('2022-03-10'),
 *   months: 4
 * } 
 */

export async function queryPostCountStatsFunction(options) {
  try {
    const result = await posts.queryPostCountStats(options);
    const stats = result.stats;
    const firstMonthPostCount = result.stats[0].postCount;
    console.log('Retrieved Result:', result);
    return result;
  } catch (error) {
    console.error(error);
  }
}

/* Promise resolves to:
 * {
 *  "stats": [
 *    {
 *      "periodStart": "2022-03-01T00:00:00.000Z",
 *      "postCount": 9
 *    },
 *    {
 *      "periodStart": "2022-04-01T00:00:00.000Z",
 *      "postCount": 6
 *    },
 *    {
 *      "periodStart": "2022-05-01T00:00:00.000Z",
 *      "postCount": 1
 *    },
 *    {
 *      "periodStart": "2022-06-01T00:00:00.000Z",
 *      "postCount": 2
 *    }
 *  ]
 * }
 */
```

### Get post count per month
This example uses `queryPostCountStats()` to retrieve the `postCount` of published posts per month.

```javascript
import { posts } from '@wix/blog';

export async function queryPostCountStatsFunction() {
  try {
    const result = await posts.queryPostCountStats();
    const stats = result.stats;
    const firstMonthPostCount = result.stats[0].postCount;
    console.log('Retrieved Result:',result);
    return result;
  } catch (error) {
    console.error(error);
  };
}

/* Promise resolves to:
 * {
 *   "stats": [
 *     {
 *       "periodStart": "2020-08-01T00:00:00.000Z",
 *       "postCount": 1
 *     },
 *     {
 *       "periodStart": "2021-03-01T00:00:00.000Z",
 *       "postCount": 2
 *     },
 *     {
 *       "periodStart": "2022-03-01T00:00:00.000Z",
 *       "postCount": 9
 *     },
 *     {
 *       "periodStart": "2022-04-01T00:00:00.000Z",
 *       "postCount": 6
 *     },
 *     {
 *       "periodStart": "2022-05-01T00:00:00.000Z",
 *       "postCount": 1
 *     },
 *     {
 *       "periodStart": "2022-06-01T00:00:00.000Z",
 *       "postCount": 2
 *     },
 *     {
 *       "periodStart": "2022-07-01T00:00:00.000Z",
 *       "postCount": 5
 *     }
 *   ]
 * }
 */
```

### queryPostCountStats (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { posts } from '@wix/blog';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { posts },
  // Include the auth strategy and host as relevant
});


async function queryPostCountStats(options) {
  const response = await myWixClient.posts.queryPostCountStats(options);
};
```

---