USA News — Read API Contract¶
Documentation for all GET (read-only) endpoints exposed for USA News content. This is intended for a downstream service that will consume this API for reading only — no creation or mutation endpoints are described here.
All endpoints live under the router prefix:
/api/usanews-posts
1. Conventions¶
Base URL¶
https://admin-prd.dadsnews.com/api/usanews-posts
admin-prd.dadsnews.com is the production host. A separate staging host exists for the stg
environment. The service listens on port 8080 behind a reverse proxy. CORS is restricted by
origin to localhost/127.0.0.1 and any https://*.skyneto.com host.
Authentication — REQUIRED on every request¶
Every request (including GET) must send an API key header:
x-api-key: <GET_API_KEY>
- The key used for GET requests is the dedicated read key (
get_keyin Secrets Manager, path/{env}/tiktok-api/admin-api-keys). It is different from the write key used for POST/PUT/PATCH. - Missing header →
400 Bad Request{"detail": "Missing 'x-api-key' header"}. - Wrong/invalid key on a GET →
401 Unauthorized{"detail": "Unauthorized for GET actions"}. OPTIONS(CORS preflight) requests bypass the key check.
Example:
curl --location 'https://admin-prd.dadsnews.com/api/usanews-posts/categories' \
--header 'x-api-key: API'
Content type¶
All responses are application/json.
Trailing slash¶
The list endpoint is registered at /api/usanews-posts/ (with trailing slash). A request to
/api/usanews-posts (no slash) is answered with a 307 Temporary Redirect to the slashed URL.
Prefer calling the canonical paths exactly as documented.
Date / time format¶
- All datetimes are ISO 8601 and represent naive UTC (no timezone offset is stored or
returned), e.g.
2026-06-11T14:30:00. - For query params that take a datetime (
since), send ISO 8601. AZsuffix / offset is accepted on input and normalized to UTC.
Data freshness (caching)¶
Reads are served from in-memory caches that refresh on a timer, so data can be slightly stale:
| Data | Source | Refresh interval |
|---|---|---|
| Posts list & lookups | in-memory cache (full table) | every 10 min (600s) |
| Categories | in-memory cache | every 60 min (3600s) |
CTR-ranked list (sort_by=ctr) |
DB query, cached per filter combination | 5 min (300s) TTL |
The CTR ranking is frozen per unique filter combination for the TTL: within those 5 minutes the same filter set returns the same ordered list (pagination slices that frozen list), even if underlying click data changed.
The journey tag (date override)¶
Posts whose tags array contains "journey" (case-insensitive) have their published_at,
created_at, and updated_at overridden to the current server time (UTC) when returned by:
GET /(default ordering mode only)GET /slug/{slug}GET /{post_id}
Important: this override is display-only. The list is still sorted by the real
published_at before the dates are rewritten, so ordering is unaffected — only the shown date
changes. The override is NOT applied in CTR mode (sort_by=ctr) nor in
GET /new-articles-count (which counts against the real published_at).
2. Endpoints¶
2.1 GET / — List posts¶
Returns a paginated, filtered list of posts. Two ordering modes:
- Default (recency): ordered by
published_at DESC, thenid DESC. Served from cache. - CTR (
sort_by=ctr): ordered by click-through rate. Served from the DB and supports extra ranking filters.
Response model: List[UsaNewsPostWithCtr] (see Schemas). In default mode the CTR
fields (ctr, total_clicks, total_users_sent) are null.
Query parameters¶
| Param | Type | Default | Constraints | Applies to | Description |
|---|---|---|---|---|---|
page |
int | 1 |
>= 1 |
both | 1-based page number. |
per_page |
int | 20 |
1–200 |
both | Page size. |
status |
string | published |
— | both | Filter by status. Valid values: published, draft, trash. In default mode an unknown value matches nothing (empty list); in CTR mode an unknown value is treated as "no status filter". |
is_active |
bool | true |
— | both | Filter by active flag. Accepts true/false, 1/0. Default returns only active posts. |
state |
string | — | — | both | Keep posts having a location whose state equals this (exact match). |
city |
string | — | — | both | Keep posts having a location whose city equals this (exact match). |
author_id |
string | — | — | both | Exact match on author_id. |
post_type |
string | — | — | both | Exact match on post_type. |
post_origin |
string | — | — | both | Exact match on post_origin. |
primary_category_slug |
string | — | — | both | Exact match on the post's primary category slug. |
category_slug |
string | — | — | both | Keep posts that belong to a category with this slug (any of categories[]). |
exclude_category_slug |
string (repeatable) | — | — | both | Exclude posts that belong to any category with one of these slugs (matched against categories[]). Repeat the param for multiple: ?exclude_category_slug=a&exclude_category_slug=b. Applied independently of category_slug; if a post matches both, the exclusion wins. |
tag_slug |
string | — | — | both | Keep posts whose tags[] array contains this exact string. |
sort_by |
string | — | — | switch | Set to ctr to enable CTR ranking mode. Any other value (or omitted) → default recency ordering. |
order |
string | desc |
asc/desc |
CTR only | CTR sort direction. Any value other than asc is treated as desc. |
window_minutes |
int | — | >= 1 |
CTR only | Only include posts published within the last N minutes. |
segment_name |
string (repeatable) | — | — | CTR only | Restrict click/sent aggregation to these OneSignal segment names. Repeat the param for multiple values: ?segment_name=a&segment_name=b. |
min_ctr |
float | — | >= 0 |
CTR only | Minimum CTR threshold. Posts with zero clicks are still kept regardless of this value. |
Notes:
- window_minutes, segment_name, min_ctr, and order are only honored when
sort_by=ctr. They are accepted but ignored in default mode.
- In default mode, if the post cache is empty the endpoint returns 404
{"detail": "No UsaNews Posts Available!"}.
CTR ranking semantics (sort_by=ctr)¶
ctr = SUM(clicks) / NULLIF(SUM(users_sent), 0) aggregated from push-notification metrics
(optionally filtered to segment_name). Ordering buckets:
- Posts with
total_clicks > 0(sorted byctr, direction =order), - then posts with no metrics at all,
- then posts with metrics but zero clicks;
within each bucket ties break by published_at DESC, id DESC.
Examples¶
# Latest published, active posts (default)
curl -H "x-api-key: $KEY" \
"https://admin-prd.dadsnews.com/api/usanews-posts/?page=1&per_page=20"
# Filter by category + state
curl -H "x-api-key: $KEY" \
"https://admin-prd.dadsnews.com/api/usanews-posts/?category_slug=sports&state=California"
# Exclude one or more categories
curl -H "x-api-key: $KEY" \
"https://admin-prd.dadsnews.com/api/usanews-posts/?exclude_category_slug=politics&exclude_category_slug=opinion"
# CTR ranking, last 24h, two segments, min CTR 0.05
curl -H "x-api-key: $KEY" \
"https://admin-prd.dadsnews.com/api/usanews-posts/?sort_by=ctr&order=desc&window_minutes=1440&segment_name=us_all&segment_name=ca_users&min_ctr=0.05"
2.2 GET /categories — List categories¶
Returns all categories ordered by display_order ASC, then name ASC. Served from cache.
- Query parameters: none.
- Response model:
List[UsaNewsCategory].
curl -H "x-api-key: $KEY" "https://admin-prd.dadsnews.com/api/usanews-posts/categories"
[
{ "id": 1, "slug": "politics", "name": "Politics", "display_order": 1 },
{ "id": 2, "slug": "sports", "name": "Sports", "display_order": 2 }
]
2.3 GET /new-articles-count — Count new articles¶
Counts cached posts that are published, is_active = true, and have published_at strictly
greater than the since timestamp. Useful for a "N new articles" badge.
| Param | Type | Required | Description |
|---|---|---|---|
since |
datetime (ISO 8601) | yes | Lower bound (exclusive) compared against the real published_at. |
- Response model:
UsaNewsNewArticlesCount→{ "count": <int> }. - The
journeydate override does not affect this count (it compares the realpublished_at). - A missing or unparseable
since→422 Unprocessable Entity.
curl -H "x-api-key: $KEY" \
"https://admin-prd.dadsnews.com/api/usanews-posts/new-articles-count?since=2026-06-11T00:00:00"
{ "count": 12 }
2.4 GET /slug/{slug} — Get one post by slug¶
Returns a single post by its slug. Matching is case-insensitive and trimmed. Looks in the cache first, then falls back to the DB.
- Path param:
slug(string). - Response model:
UsaNewsPost. 404 Not Found{"detail": "Post not found: <slug>"}if no match.journeydate override applies.
curl -H "x-api-key: $KEY" \
"https://admin-prd.dadsnews.com/api/usanews-posts/slug/my-article-slug"
2.5 GET /{original_post_id} — Get one post by original (source) ID¶
Returns a single post looked up by its original_post_id (the upstream/source post id),
not the internal primary key id. Looks in the cache first, then falls back to the DB.
- Path param:
original_post_id(integer — non-integer values do not match this route). - Response model:
UsaNewsPost. 404 Not Found{"detail": "Post not found: <original_post_id>"}if no post has thatoriginal_post_id.journeydate override applies.
Note: the path value is matched against
usanews_posts.original_post_id(unique). The internal primary key (id) is still present in the response body but is not the lookup key for this endpoint. Posts with anulloriginal_post_idare not retrievable here.
curl -H "x-api-key: $KEY" \
"https://admin-prd.dadsnews.com/api/usanews-posts/90871"
3. Schemas¶
UsaNewsPost¶
Returned by GET /slug/{slug} and GET /{post_id}, and is the base of each list item.
| Field | Type | Notes |
|---|---|---|
id |
int | Internal primary key. |
original_post_id |
int | null | Upstream/source post id (unique). |
slug |
string | Unique URL slug. |
title |
string | |
excerpt |
string | null | |
content |
string | null | Full HTML/long content. |
featured_media_resource_id |
int | null | |
status |
string | published | draft | trash. |
is_active |
bool | |
author_id |
string | null | Always serialized as a string. |
author_name |
string | null | |
primary_category_id |
int | null | |
primary_category_slug |
string | null | |
source_name |
string | null | From the linked source. |
source_icon_url |
string | null | |
source_link |
string | null | |
canonical_url |
string | null | |
featured_image |
object | null | { "media_url": string\|null, "low_media_url": string\|null }. null when there is no featured media. |
featured_image_alt |
string | null | Alt text for the featured image. |
categories |
UsaNewsCategory[] | May be empty. |
locations |
UsaNewsPostLocation[] | May be empty. |
tags |
string[] | May be empty. Contains the journey marker when applicable. |
published_at |
datetime | UTC. Overridden to "now" for journey posts (display-only). |
post_type |
string | |
post_origin |
string | |
created_at |
datetime | UTC. Overridden for journey posts. |
updated_at |
datetime | UTC. Overridden for journey posts. |
UsaNewsPostWithCtr¶
Returned by GET / (list). Extends UsaNewsPost with:
| Field | Type | Notes |
|---|---|---|
ctr |
float | null | Populated only in CTR mode. |
total_clicks |
int | null | Populated only in CTR mode. |
total_users_sent |
int | null | Populated only in CTR mode. |
In default mode these three fields are null.
UsaNewsCategory¶
| Field | Type | Notes |
|---|---|---|
id |
int | null | |
slug |
string | |
name |
string | |
display_order |
int | null |
UsaNewsPostLocation¶
| Field | Type | Notes |
|---|---|---|
state |
string | null | |
city |
string | null |
UsaNewsNewArticlesCount¶
| Field | Type | Notes |
|---|---|---|
count |
int |
Example post object¶
{
"id": 22473,
"original_post_id": 90871,
"slug": "example-article",
"title": "Example Article",
"excerpt": "Short summary…",
"content": "<p>Full HTML…</p>",
"featured_media_resource_id": 23608,
"status": "published",
"is_active": true,
"author_id": "108",
"author_name": "Jane Doe",
"primary_category_id": 2,
"primary_category_slug": "sports",
"source_name": "Example Source",
"source_icon_url": "https://cdn.example.com/icon.png",
"source_link": "https://example.com",
"canonical_url": "https://example.com/example-article",
"featured_image": {
"media_url": "https://assets-prd.dadsnews.com/usanews/abc-optimize.jpg",
"low_media_url": "https://assets-prd.dadsnews.com/usanews/abc-small.jpg"
},
"featured_image_alt": "A descriptive alt text",
"categories": [
{ "id": 2, "slug": "sports", "name": "Sports", "display_order": 2 }
],
"locations": [
{ "state": "California", "city": "Los Angeles" }
],
"tags": ["nba", "playoffs"],
"published_at": "2026-06-10T18:00:00",
"post_type": "article",
"post_origin": "wordpress",
"created_at": "2026-06-10T18:01:12",
"updated_at": "2026-06-10T18:05:30",
"ctr": 0.123,
"total_clicks": 246,
"total_users_sent": 2000
}
4. Error responses¶
All errors return JSON shaped as {"detail": <string|array>}.
| Status | When |
|---|---|
400 Bad Request |
Missing x-api-key header. |
401 Unauthorized |
Wrong key for a GET request. |
404 Not Found |
Post not found (by id/slug); or no posts available for GET / in default mode. |
422 Unprocessable Entity |
Query/path validation failed (e.g. page < 1, per_page > 200, malformed since, non-integer post_id). FastAPI's standard validation error array. |
500 Internal Server Error |
Unexpected server error. |
5. Endpoint quick reference¶
| Method | Path | Purpose |
|---|---|---|
| GET | /api/usanews-posts/ |
List posts (filters, pagination, recency or CTR ordering). |
| GET | /api/usanews-posts/categories |
List all categories. |
| GET | /api/usanews-posts/new-articles-count?since=<dt> |
Count new published+active posts since a datetime. |
| GET | /api/usanews-posts/slug/{slug} |
Get one post by slug (case-insensitive). |
| GET | /api/usanews-posts/{original_post_id} |
Get one post by its original_post_id (source id), not the internal id. |