{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/postzen-dev/json-schema/postzen-dev-analytics-list-response-schema.json",
  "title": "AnalyticsListResponse",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/postzen-dev-analytics-api-openapi.yml#/components/schemas/AnalyticsListResponse",
  "type": "object",
  "required": [
    "posts",
    "pagination",
    "overview",
    "truncated"
  ],
  "properties": {
    "posts": {
      "type": "array",
      "description": "One entry per PostZen post, not per platform target. A post published to several platforms appears once, with one `platformAnalytics` entry per platform and `analytics` summed across them; `platform` is that post's only platform when it has one. Posts imported from a platform always appear on their own. `pagination.total` and `overview.totalPosts` count these grouped entries.",
      "items": {
        "$ref": "#/$defs/AnalyticsPost"
      }
    },
    "pagination": {
      "$ref": "#/$defs/Pagination"
    },
    "overview": {
      "$ref": "#/$defs/AnalyticsOverview"
    },
    "truncated": {
      "type": "boolean",
      "description": "True when the requested window contained more posts than a single response can scan. `pagination.total` and `overview` then describe the most recent slice of the window rather than all of it; narrow `fromDate`/`toDate`, `accountId`, or `platform` to get exact totals."
    }
  },
  "$defs": {
    "AnalyticsMediaItem": {
      "type": "object",
      "required": [
        "type",
        "url",
        "thumbnail"
      ],
      "properties": {
        "type": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "thumbnail": {
          "type": "string",
          "format": "uri"
        }
      }
    },
    "AnalyticsMetricTotals": {
      "type": "object",
      "description": "The eight normalized metrics returned for every platform. A platform that reports a single view count returns it in both `views` and `impressions`. A metric the platform does not report is returned as `0`, so check the per-platform coverage in the API reference before reading a zero as no activity. `reach` is currently reported for Instagram only.",
      "required": [
        "impressions",
        "reach",
        "likes",
        "comments",
        "shares",
        "saves",
        "clicks",
        "views"
      ],
      "properties": {
        "impressions": {
          "type": "number"
        },
        "reach": {
          "type": "number"
        },
        "likes": {
          "type": "number"
        },
        "comments": {
          "type": "number"
        },
        "shares": {
          "type": "number"
        },
        "saves": {
          "type": "number"
        },
        "clicks": {
          "type": "number"
        },
        "views": {
          "type": "number"
        }
      }
    },
    "AnalyticsMetrics": {
      "allOf": [
        {
          "$ref": "#/$defs/AnalyticsMetricTotals"
        },
        {
          "type": "object",
          "required": [
            "engagementRate",
            "lastUpdated"
          ],
          "properties": {
            "engagementRate": {
              "type": "number",
              "description": "Interactions (likes + comments + shares + saves + clicks) divided by impressions, multiplied by 100 and rounded to two decimals. On platforms that report no impressions, such as Bluesky, the value is the interaction count multiplied by 100 and is not a rate."
            },
            "lastUpdated": {
              "type": [
                "string",
                "null"
              ],
              "format": "date-time"
            }
          }
        }
      ]
    },
    "AnalyticsOverview": {
      "type": "object",
      "required": [
        "totalPosts",
        "totals",
        "avgEngagementRate"
      ],
      "properties": {
        "totalPosts": {
          "type": "number"
        },
        "totals": {
          "$ref": "#/$defs/AnalyticsMetricTotals"
        },
        "avgEngagementRate": {
          "type": "number"
        }
      }
    },
    "AnalyticsPlatform": {
      "type": "string",
      "enum": [
        "x",
        "instagram",
        "tiktok",
        "linkedin",
        "facebook",
        "youtube",
        "threads",
        "pinterest",
        "bluesky",
        "telegram"
      ]
    },
    "AnalyticsPost": {
      "type": "object",
      "required": [
        "postId",
        "postzenPostId",
        "status",
        "content",
        "scheduledFor",
        "publishedAt",
        "analytics",
        "platformAnalytics",
        "platform",
        "platformPostUrl",
        "isExternal",
        "syncStatus",
        "message",
        "thumbnailUrl",
        "mediaType",
        "mediaItems"
      ],
      "properties": {
        "postId": {
          "type": "string"
        },
        "postzenPostId": {
          "type": [
            "string",
            "null"
          ]
        },
        "status": {
          "type": "string"
        },
        "content": {
          "type": "string"
        },
        "scheduledFor": {
          "type": "string",
          "format": "date-time"
        },
        "publishedAt": {
          "type": "string",
          "format": "date-time"
        },
        "analytics": {
          "$ref": "#/$defs/AnalyticsMetrics"
        },
        "platformAnalytics": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/PlatformAnalytics"
          }
        },
        "platform": {
          "$ref": "#/$defs/AnalyticsPlatform"
        },
        "platformPostUrl": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri"
        },
        "isExternal": {
          "type": "boolean"
        },
        "syncStatus": {
          "type": "string",
          "enum": [
            "synced",
            "pending",
            "failed"
          ]
        },
        "message": {
          "type": [
            "string",
            "null"
          ]
        },
        "thumbnailUrl": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri"
        },
        "mediaType": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "image",
            "video",
            "text",
            "carousel",
            null
          ]
        },
        "mediaItems": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AnalyticsMediaItem"
          }
        }
      }
    },
    "Pagination": {
      "type": "object",
      "required": [
        "page",
        "limit",
        "total",
        "totalPages"
      ],
      "properties": {
        "page": {
          "type": "integer",
          "minimum": 1
        },
        "limit": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100
        },
        "total": {
          "type": "integer",
          "minimum": 0
        },
        "totalPages": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "PlatformAnalytics": {
      "type": "object",
      "required": [
        "platform",
        "status",
        "platformPostId",
        "accountId",
        "accountUsername",
        "analytics",
        "syncStatus",
        "platformPostUrl",
        "errorMessage"
      ],
      "properties": {
        "platform": {
          "$ref": "#/$defs/AnalyticsPlatform"
        },
        "status": {
          "type": "string"
        },
        "platformPostId": {
          "type": "string"
        },
        "accountId": {
          "type": "string"
        },
        "accountUsername": {
          "type": "string"
        },
        "analytics": {
          "$ref": "#/$defs/AnalyticsMetrics"
        },
        "syncStatus": {
          "type": "string",
          "enum": [
            "synced",
            "pending",
            "failed"
          ]
        },
        "platformPostUrl": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri"
        },
        "errorMessage": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    }
  }
}