Skip to main content

Endpoint

POST https://api.ugc.inc/stats/posts

Overview

Get post statistics including views, likes, comments, and shares. Behavior:
  • If startDate and endDate are NOT provided: Returns the latest stat per post (one record per post) - optimal for dashboards showing current state
  • If startDate or endDate is provided: Returns all stats within the date range - use for historical analysis and trend tracking
Use this endpoint to track post performance over time.

Request Body

postIds
string[]
Array of post IDs to get stats for. Omit to get all posts.
startDate
string
Start date in ISO 8601 format (e.g., 2024-01-01T00:00:00Z). Optional. If omitted (along with endDate), returns latest stat per post.
endDate
string
End date in ISO 8601 format (e.g., 2024-12-31T23:59:59Z). Optional. If omitted (along with startDate), returns latest stat per post.

Response

data
PostStat[]
Array of post statistics objects
curl -X POST https://api.ugc.inc/stats/posts \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "postIds": ["post_123456", "post_789012"],
    "startDate": "2024-01-01T00:00:00Z",
    "endDate": "2024-12-31T23:59:59Z"
  }'
import requests

response = requests.post(
    'https://api.ugc.inc/stats/posts',
    headers={
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
    },
    json={
        'postIds': ['post_123456', 'post_789012'],
        'startDate': '2024-01-01T00:00:00Z',
        'endDate': '2024-12-31T23:59:59Z'
    }
)

data = response.json()

if data['ok']:
    for stat in data['data']:
        print(f"Post {stat['post_id']}: {stat['views']} views, {stat['likes']} likes")
const response = await fetch('https://api.ugc.inc/stats/posts', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    postIds: ['post_123456', 'post_789012'],
    startDate: '2024-01-01T00:00:00Z',
    endDate: '2024-12-31T23:59:59Z'
  })
});

const data = await response.json();

if (data.ok) {
  data.data.forEach(stat => {
    console.log(`Post ${stat.post_id}:`);
    console.log(`  Views: ${stat.views}`);
    console.log(`  Likes: ${stat.likes}`);
    console.log(`  Comments: ${stat.comments}`);
  });
}
import { UGCClient } from 'ugcinc';

const client = new UGCClient({
  apiKey: 'YOUR_API_KEY'
});

const response = await client.stats.getPostStats({
  postIds: ['post_123456', 'post_789012'],
  startDate: '2024-01-01T00:00:00Z',
  endDate: '2024-12-31T23:59:59Z'
});

if (response.ok) {
  response.data.forEach(stat => {
    console.log(`Post ${stat.post_id}: ${stat.views} views, ${stat.likes} likes`);
  });
}
{
  "ok": true,
  "code": 200,
  "message": "Success",
  "data": [
    {
      "id": "pstat_abc123",
      "post_id": "post_123456",
      "views": 125000,
      "likes": 8950,
      "comments": 342,
      "shares": 567,
      "created_at": "2024-12-25T10:00:00Z"
    },
    {
      "id": "pstat_def456",
      "post_id": "post_123456",
      "views": 128500,
      "likes": 9120,
      "comments": 356,
      "shares": 589,
      "created_at": "2024-12-26T10:00:00Z"
    }
  ]
}