GET /sites/$site/stats/post/$post_id

View a post's views

Resource Information

   
Method GET
URL https://public-api.wordpress.com/rest/v1.1/sites/$site/stats/post/$post_id
Requires authentication? Yes

Method Parameters

Parameter Type Description
$site (int|string) The site's id or domain
$post_id (int) The post's id

Query Parameters

Parameter Type Description
context (string)
display:
(default) Formats the output as HTML for display. Shortcodes are parsed, paragraph tags are added, etc..
edit:
Formats the output for editing. Shortcodes are left unparsed, significant whitespace is kept, etc..
http_envelope (bool)
false:
(default)
true:
Some environments (like in-browser Javascript or Flash) block or divert responses with a non-200 HTTP status code. Setting this parameter will force the HTTP status code to always be 200. The JSON response is wrapped in an "envelope" containing the "real" HTTP status code and headers.
pretty (bool)
false:
(default)
true:
Output pretty JSON
meta (string) Optional. Loads data from the endpoints found in the 'meta' part of the response. Comma-separated list. Example: meta=site,likes
fields (string) Optional. Returns specified fields only. Comma-separated list. Example: fields=ID,title
callback (string) An optional JSONP callback function.

Response Parameters

Parameter Type Description
date (string) The most-recent day for which stats are returned
years (array) Views grouped by years and months
averages (array) Per-day average of views grouped by years and months
weeks (array) Daily views for recent weeks

Resource Errors

These are the possible errors returned by this endpoint.

HTTP Code Error Identifier Error Message
403 unauthorized User cannot access this private blog.
403 unauthorized User cannot access this restricted blog
403 unauthorized user cannot view stats
404 unknown_post Unknown post

Example

curl \
 -H 'authorization: Bearer YOUR_API_TOKEN' \
 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/stats/post/843'
<?php
$options  = array (
  'http' => 
  array (
    'ignore_errors' => true,
    'header' => 
    array (
      0 => 'authorization: Bearer YOUR_API_TOKEN',
    ),
  ),
);

$context  = stream_context_create( $options );
$response = file_get_contents(
	'https://public-api.wordpress.com/rest/v1.1/sites/82974409/stats/post/843',
	false,
	$context
);
$response = json_decode( $response );
?>

Response

{
    "date": "2015-04-19",
    "views": 0,
    "years": {
        "1970": {
            "months": [],
            "total": 0
        },
        "1971": {
            "months": [],
            "total": 0
        },
        "1972": {
            "months": [],
            "total": 0
        },
        "1973": {
            "months": [],
            "total": 0
        },
        "1974": {
            "months": [],
            "total": 0
        },
        "1975": {
            "months": [],
            "total": 0
        },
        "1976": {
            "months": [],
            "total": 0
        },
        "1977": {
            "months": [],
            "total": 0
        },
        "1978": {
            "months": [],
            "total": 0
        },
        "1979": {
            "months": [],
            "total": 0
        },
        "1980": {
            "months": [],
            "total": 0
        },
        "1981": {
            "months": [],
            "total": 0
        },
        "1982": {
            "months": [],
            "total": 0
        },
        "1983": {
            "months": [],
            "total": 0
        },
        "1984": {
            "months": [],
            "total": 0
        },
        "1985": {
            "months": [],
            "total": 0
        },
        "1986": {
            "months": [],
            "total": 0
        },
        "1987": {
            "months": [],
            "total": 0
        },
        "1988": {
            "months": [],
            "total": 0
        },
        "1989": {
            "months": [],
            "total": 0
        },
        "1990": {
            "months": [],
            "total": 0
        },
        "1991": {
            "months": [],
            "total": 0
        },
        "1992": {
            "months": [],
            "total": 0
        },
        "1993": {
            "months": [],
            "total": 0
        },
        "1994": {
            "months": [],
            "total": 0
        },
        "1995": {
            "months": [],
            "total": 0
        },
        "1996": {
            "months": [],
            "total": 0
        },
        "1997": {
            "months": [],
            "total": 0
        },
        "1998": {
            "months": [],
            "total": 0
        },
        "1999": {
            "months": [],
            "total": 0
        },
        "2000": {
            "months": [],
            "total": 0
        },
        "2001": {
            "months": [],
            "total": 0
        },
        "2002": {
            "months": [],
            "total": 0
        },
        "2003": {
            "months": [],
            "total": 0
        },
        "2004": {
            "months": [],
            "total": 0
        },
        "2005": {
            "months": [],
            "total": 0
        },
        "2006": {
            "months": [],
            "total": 0
        },
        "2007": {
            "months": [],
            "total": 0
        },
        "2008": {
            "months": [],
            "total": 0
        },
        "2009": {
            "months": [],
            "total": 0
        },
        "2010": {
            "months": [],
            "total": 0
        },
        "2011": {
            "months": [],
            "total": 0
        },
        "2012": {
            "months": [],
            "total": 0
        },
        "2013": {
            "months": [],
            "total": 0
        },
        "2014": {
            "months": [],
            "total": 0
        },
        "2015": {
            "months": [],
            "total": 0
        }
    },
    "averages": {
        "1970": {
            "months": [],
            "overall": 0
        },
        "1971": {
            "months": [],
            "overall": 0
        },
        "1972": {
            "months": [],
            "overall": 0
        },
        "1973": {
            "months": [],
            "overall": 0
        },
        "1974": {
            "months": [],
            "overall": 0
        },
        "1975": {
            "months": [],
            "overall": 0
        },
        "1976": {
            "months": [],
            "overall": 0
        },
        "1977": {
            "months": [],
            "overall": 0
        },
        "1978": {
            "months": [],
            "overall": 0
        },
        "1979": {
            "months": [],
            "overall": 0
        },
        "1980": {
            "months": [],
            "overall": 0
        },
        "1981": {
            "months": [],
            "overall": 0
        },
        "1982": {
            "months": [],
            "overall": 0
        },
        "1983": {
            "months": [],
            "overall": 0
        },
        "1984": {
            "months": [],
            "overall": 0
        },
        "1985": {
            "months": [],
            "overall": 0
        },
        "1986": {
            "months": [],
            "overall": 0
        },
        "1987": {
            "months": [],
            "overall": 0
        },
        "1988": {
            "months": [],
            "overall": 0
        },
        "1989": {
            "months": [],
            "overall": 0
        },
        "1990": {
            "months": [],
            "overall": 0
        },
        "1991": {
            "months": [],
            "overall": 0
        },
        "1992": {
            "months": [],
            "overall": 0
        },
        "1993": {
            "months": [],
            "overall": 0
        },
        "1994": {
            "months": [],
            "overall": 0
        },
        "1995": {
            "months": [],
            "overall": 0
        },
        "1996": {
            "months": [],
            "overall": 0
        },
        "1997": {
            "months": [],
            "overall": 0
        },
        "1998": {
            "months": [],
            "overall": 0
        },
        "1999": {
            "months": [],
            "overall": 0
        },
        "2000": {
            "months": [],
            "overall": 0
        },
        "2001": {
            "months": [],
            "overall": 0
        },
        "2002": {
            "months": [],
            "overall": 0
        },
        "2003": {
            "months": [],
            "overall": 0
        },
        "2004": {
            "months": [],
            "overall": 0
        },
        "2005": {
            "months": [],
            "overall": 0
        },
        "2006": {
            "months": [],
            "overall": 0
        },
        "2007": {
            "months": [],
            "overall": 0
        },
        "2008": {
            "months": [],
            "overall": 0
        },
        "2009": {
            "months": [],
            "overall": 0
        },
        "2010": {
            "months": [],
            "overall": 0
        },
        "2011": {
            "months": [],
            "overall": 0
        },
        "2012": {
            "months": [],
            "overall": 0
        },
        "2013": {
            "months": [],
            "overall": 0
        },
        "2014": {
            "months": [],
            "overall": 0
        },
        "2015": {
            "months": [],
            "overall": 0
        }
    },
    "weeks": [
        {
            "days": [
                {
                    "day": "2015-03-09",
                    "count": 0
                },
                {
                    "day": "2015-03-10",
                    "count": 0
                },
                {
                    "day": "2015-03-11",
                    "count": 0
                },
                {
                    "day": "2015-03-12",
                    "count": 0
                },
                {
                    "day": "2015-03-13",
                    "count": 0
                },
                {
                    "day": "2015-03-14",
                    "count": 0
                },
                {
                    "day": "2015-03-15",
                    "count": 0
                }
            ],
            "total": 0,
            "average": 0,
            "change": null
        },
        {
            "days": [
                {
                    "day": "2015-03-16",
                    "count": 0
                },
                {
                    "day": "2015-03-17",
                    "count": 0
                },
                {
                    "day": "2015-03-18",
                    "count": 0
                },
                {
                    "day": "2015-03-19",
                    "count": 0
                },
                {
                    "day": "2015-03-20",
                    "count": 0
                },
                {
                    "day": "2015-03-21",
                    "count": 0
                },
                {
                    "day": "2015-03-22",
                    "count": 0
                }
            ],
            "total": 0,
            "average": 0,
            "change": 0
        },
        {
            "days": [
                {
                    "day": "2015-03-23",
                    "count": 0
                },
                {
                    "day": "2015-03-24",
                    "count": 0
                },
                {
                    "day": "2015-03-25",
                    "count": 0
                },
                {
                    "day": "2015-03-26",
                    "count": 0
                },
                {
                    "day": "2015-03-27",
                    "count": 0
                },
                {
                    "day": "2015-03-28",
                    "count": 0
                },
                {
                    "day": "2015-03-29",
                    "count": 0
                }
            ],
            "total": 0,
            "average": 0,
            "change": 0
        },
        {
            "days": [
                {
                    "day": "2015-03-30",
                    "count": 0
                },
                {
                    "day": "2015-03-31",
                    "count": 0
                },
                {
                    "day": "2015-04-01",
                    "count": 0
                },
                {
                    "day": "2015-04-02",
                    "count": 0
                },
                {
                    "day": "2015-04-03",
                    "count": 0
                },
                {
                    "day": "2015-04-04",
                    "count": 0
                },
                {
                    "day": "2015-04-05",
                    "count": 0
                }
            ],
            "total": 0,
            "average": 0,
            "change": 0
        },
        {
            "days": [
                {
                    "day": "2015-04-06",
                    "count": 0
                },
                {
                    "day": "2015-04-07",
                    "count": 0
                },
                {
                    "day": "2015-04-08",
                    "count": 0
                },
                {
                    "day": "2015-04-09",
                    "count": 0
                },
                {
                    "day": "2015-04-10",
                    "count": 0
                },
                {
                    "day": "2015-04-11",
                    "count": 0
                },
                {
                    "day": "2015-04-12",
                    "count": 0
                }
            ],
            "total": 0,
            "average": 0,
            "change": 0
        },
        {
            "days": [
                {
                    "day": "2015-04-13",
                    "count": 0
                },
                {
                    "day": "2015-04-14",
                    "count": 0
                },
                {
                    "day": "2015-04-15",
                    "count": 0
                },
                {
                    "day": "2015-04-16",
                    "count": 0
                },
                {
                    "day": "2015-04-17",
                    "count": 0
                },
                {
                    "day": "2015-04-18",
                    "count": 0
                },
                {
                    "day": "2015-04-19",
                    "count": 0
                }
            ],
            "total": 0,
            "average": 0,
            "change": 0
        }
    ],
    "fields": [
        "period",
        "views"
    ],
    "data": [
        [
            "2015-04-18",
            0
        ],
        [
            "2015-04-19",
            0
        ]
    ],
    "highest_month": 0,
    "highest_day_average": 0,
    "highest_week_average": 0,
    "post": {
        "ID": 843,
        "post_author": "78972699",
        "post_date": "2015-04-18 18:39:16",
        "post_date_gmt": "2015-04-18 18:39:16",
        "post_content": "Meow.",
        "post_title": "Cats are awesome.",
        "post_excerpt": "",
        "post_status": "publish",
        "comment_status": "open",
        "ping_status": "open",
        "post_password": "",
        "post_name": "cats-are-awesome",
        "to_ping": "",
        "pinged": "",
        "post_modified": "2015-04-18 18:39:16",
        "post_modified_gmt": "2015-04-18 18:39:16",
        "post_content_filtered": "",
        "post_parent": 0,
        "guid": "https:\/\/apiexamples.wordpress.com\/?p=843",
        "menu_order": 0,
        "post_type": "post",
        "post_mime_type": "",
        "comment_count": "9",
        "filter": "raw",
        "permalink": "http:\/\/apiexamples.wordpress.com\/2015\/04\/18\/cats-are-awesome\/"
    }
}