Custom REST routes for post analytics queries and Civis CSV exports.
Base path: /wp-json/prc-api/v3/
Admin settings also expose GET/POST /wp-json/prc-analytics/v1/settings and POST .../settings/generate-civis-key for manage_options users. Those power the Settings UI and are not documented as a public contract here.
Auth summary
| Access | Routes |
|---|---|
edit_posts | POST /analytics/query-by-url/, GET /analytics/query/ |
X-Civis-API-Key header | GET /analytics/civis/* |
POST /analytics/query-by-url/
Returns post metadata plus Parse.ly metrics for a single URL.
Permission: current_user_can( 'edit_posts' )
Request body
-
urlurl required -
Canonical post URL to resolve.
No fields match this filter.
/wp-json/prc-api/v3/analytics/query-by-url/
Content-Type application/jsonAccept application/json{
"url": "https://alpha.pewresearch.org/pewresearch-org/example-article/"
}
{
"id": 123,
"title": "Example",
"parsely_metrics": {},
"word_count": 1200
}Response fields include id, parent_id, date_published, date_modified, content, title, bylines, label (format taxonomy), topics, primary_topic, research_teams, parsely_metrics, word_count.
Errors: WP_Error code 404 for malformed requests, missing URL, or URL helper failures.
GET /analytics/query/
Paginated list of posts with metadata and Parse.ly metrics (25 per page).
Permission: current_user_can( 'edit_posts' )
Query parameters
-
post_typestring -
Comma-separated post types.
-
pagenumber -
Page number.
-
start_datestring -
strtotime()-compatible inclusive start.
-
end_datestring -
Inclusive end; defaults to today when start_date is set.
-
research_teamstring -
Research team taxonomy slug.
-
return_only_correctionsboolean -
Limit to posts containing correction in the body.
No fields match this filter.
Civis export routes
All Civis routes require header X-Civis-API-Key: <key> validated by API_Key_Auth. Responses are text/csv with X-Total-Count and X-Has-More. Common params: limit (default 1000, max 10000), offset.
| Method | Path | Description |
|---|---|---|
GET | /analytics/civis/datasets | Dataset download stats (day or month rows) |
GET | /analytics/civis/users | User rows from Firebase |
GET | /analytics/civis/quiz-groups | Quiz group aggregates; optional quiz_id |
GET | /analytics/civis/quiz-submissions | Individual submissions; optional quiz_id |
Auth errors
| Code | Status | Meaning |
|---|---|---|
civis_api_key_not_configured | 500 | No key saved in settings |
civis_api_key_missing | 401 | Header absent |
civis_api_key_invalid | 401 | Header does not match |
Users and quiz exports may also return firebase_not_available, firebase_not_configured, or firebase_error (500).
/wp-json/prc-api/v3/analytics/civis/datasets?limit=100&offset=0
X-Civis-API-Key your-key-hereAccept text/csv
day,daily_count,new_data_uploaded
2024-01-01,12,true