{
  "openapi": "3.1.0",
  "info": {
    "title": "Analystic API",
    "version": "1.0.0",
    "description": "Analystic Automation API v1 (client configuration, organization metadata) and Reporting API v1 (normalized, read-only report data). Server-to-server: Bearer organization tokens created in Analystic → Automations. Rates are decimal ratios (0.1234 = 12.34 %), durations are seconds, money is { value, currency }; null = not available, 0 = measured zero. Resources (GA4 properties, Search Console sites, Google Ads accounts) are never summed and currencies never mixed. Examples use a fictional client (Nordvik Studio AB)."
  },
  "servers": [
    {
      "url": "https://analystic.dev"
    }
  ],
  "tags": [
    {
      "name": "Reporting"
    },
    {
      "name": "Automation"
    }
  ],
  "paths": {
    "/api/reporting/v1/reports": {
      "get": {
        "tags": [
          "Reporting"
        ],
        "summary": "Reports, periods and comparisons this token can use (no data)",
        "operationId": "reportDiscovery",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-required-scope": "reports:read",
        "responses": {
          "200": {
            "description": "Discovery",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/BillingRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/reporting/v1/clients/{client}/reports/{report}": {
      "get": {
        "tags": [
          "Reporting"
        ],
        "summary": "A client's report (Agency organizations)",
        "operationId": "clientReport",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-required-scope": "reports:read",
        "parameters": [
          {
            "$ref": "#/components/parameters/client"
          },
          {
            "$ref": "#/components/parameters/report"
          },
          {
            "$ref": "#/components/parameters/period"
          },
          {
            "$ref": "#/components/parameters/start"
          },
          {
            "$ref": "#/components/parameters/end"
          },
          {
            "$ref": "#/components/parameters/comparison"
          },
          {
            "$ref": "#/components/parameters/comparison_start"
          },
          {
            "$ref": "#/components/parameters/comparison_end"
          },
          {
            "$ref": "#/components/parameters/limit"
          }
        ],
        "responses": {
          "200": {
            "description": "The report (also when a source failed — see sources.*.status).",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Report"
                },
                "examples": {
                  "agencyOverview": {
                    "value": {
                      "schema_version": "1",
                      "api_version": "v1",
                      "report": "overview",
                      "request_id": "req_3f9a1c2b7d4e5f60a1b2",
                      "generated_at": "2026-10-05T09:30:00.000Z",
                      "organization": {
                        "id": "org_example",
                        "mode": "agency"
                      },
                      "client": {
                        "id": "00000000-0000-4000-8000-000000000001",
                        "external_key": "crm-1042",
                        "name": "Nordvik Studio AB",
                        "domain": "nordvik.example"
                      },
                      "business_model": {
                        "value": "lead_generation",
                        "complete": true
                      },
                      "period": {
                        "start": "2026-09-01",
                        "end": "2026-09-30",
                        "days": 30,
                        "preset": "last_month"
                      },
                      "comparison": {
                        "mode": "previous_period",
                        "start": "2026-08-02",
                        "end": "2026-08-31",
                        "days": 30
                      },
                      "sources": {
                        "ga4": {
                          "configured": true,
                          "loaded": true,
                          "status": "ok",
                          "resources": [
                            {
                              "id": "00000000-0000-4000-8000-0000000000a1",
                              "property_id": "123456789",
                              "name": "Nordvik Studio – GA4",
                              "status": "ok"
                            }
                          ]
                        },
                        "search_console": {
                          "configured": true,
                          "loaded": true,
                          "status": "ok",
                          "resources": [
                            {
                              "id": "00000000-0000-4000-8000-0000000000b1",
                              "site_url": "sc-domain:nordvik.example",
                              "name": "nordvik.example",
                              "status": "ok",
                              "latest_data_date": "2026-09-30"
                            }
                          ]
                        },
                        "google_ads": {
                          "configured": true,
                          "loaded": true,
                          "status": "error",
                          "resources": [
                            {
                              "id": "00000000-0000-4000-8000-0000000000c1",
                              "customer_id": "1234567890",
                              "name": "Nordvik Studio Ads",
                              "currency": "SEK",
                              "status": "quota_exceeded",
                              "error": {
                                "kind": "quota_exceeded",
                                "message": "Google Ads temporarily limited requests"
                              }
                            }
                          ]
                        }
                      },
                      "summary": {
                        "ga4": [
                          {
                            "id": "00000000-0000-4000-8000-0000000000a1",
                            "name": "Nordvik Studio – GA4",
                            "scope": "all_traffic",
                            "metrics": {
                              "sessions": {
                                "value": 1200,
                                "comparison": 1050,
                                "change": {
                                  "absolute": 150,
                                  "percent": 14.29,
                                  "direction": "up"
                                }
                              },
                              "engagement_rate": {
                                "value": 0.6125,
                                "comparison": 0.58,
                                "change": {
                                  "absolute": 0.0325,
                                  "percent": 5.6,
                                  "direction": "up"
                                }
                              },
                              "key_events": {
                                "value": 42,
                                "comparison": 0,
                                "change": {
                                  "absolute": 42,
                                  "percent": null,
                                  "direction": "new"
                                }
                              }
                            },
                            "traffic_split": {
                              "sessions": {
                                "organic": {
                                  "value": 640,
                                  "comparison": 600,
                                  "change": {
                                    "absolute": 40,
                                    "percent": 6.67,
                                    "direction": "up"
                                  }
                                }
                              }
                            }
                          }
                        ],
                        "search_console": [
                          {
                            "id": "00000000-0000-4000-8000-0000000000b1",
                            "name": "nordvik.example",
                            "metrics": {
                              "clicks": {
                                "value": 510,
                                "comparison": 480,
                                "change": {
                                  "absolute": 30,
                                  "percent": 6.25,
                                  "direction": "up"
                                }
                              },
                              "average_position": {
                                "value": 8.4,
                                "comparison": 9.1,
                                "change": {
                                  "absolute": -0.7,
                                  "percent": -7.69,
                                  "direction": "down"
                                }
                              }
                            }
                          }
                        ],
                        "google_ads": [
                          {
                            "id": "00000000-0000-4000-8000-0000000000c1",
                            "name": "Nordvik Studio Ads",
                            "currency": "SEK",
                            "metrics": null
                          }
                        ]
                      },
                      "series": {
                        "ga4": [
                          {
                            "id": "00000000-0000-4000-8000-0000000000a1",
                            "name": "Nordvik Studio – GA4",
                            "points": [
                              {
                                "date": "2026-09-01",
                                "sessions": 41,
                                "sessions_organic": 22,
                                "sessions_paid": 9,
                                "sessions_other": 10,
                                "key_events": 1,
                                "key_events_organic": 1,
                                "key_events_paid": 0,
                                "key_events_other": 0,
                                "events": 380
                              }
                            ],
                            "comparison_points": [
                              {
                                "date": "2026-08-02",
                                "sessions": 35,
                                "sessions_organic": 20,
                                "sessions_paid": 7,
                                "sessions_other": 8,
                                "key_events": 0,
                                "key_events_organic": 0,
                                "key_events_paid": 0,
                                "key_events_other": 0,
                                "events": 300
                              }
                            ]
                          }
                        ]
                      },
                      "tables": {
                        "ga4_key_events": [
                          {
                            "id": "00000000-0000-4000-8000-0000000000a1",
                            "name": "Nordvik Studio – GA4",
                            "total_rows": 1,
                            "rows": [
                              {
                                "event_name": "generate_lead",
                                "events": 44,
                                "key_events": {
                                  "value": 42,
                                  "comparison": 0,
                                  "change": {
                                    "absolute": 42,
                                    "percent": null,
                                    "direction": "new"
                                  }
                                }
                              }
                            ]
                          }
                        ]
                      },
                      "intelligence": {
                        "checks": {
                          "total": 1,
                          "items": [
                            {
                              "id": "SOURCE_UNAVAILABLE:ads:00000000-0000-4000-8000-0000000000c1",
                              "reason_code": "SOURCE_UNAVAILABLE",
                              "kind": "measurement_check",
                              "severity": "high",
                              "title": "Google Ads data unavailable",
                              "reason": "Google Ads could not be read for this period.",
                              "source": "google_ads",
                              "resource": {
                                "id": "00000000-0000-4000-8000-0000000000c1",
                                "name": "Nordvik Studio Ads"
                              },
                              "metric": "source",
                              "value_kind": "count",
                              "currency": null,
                              "current": null,
                              "comparison": null,
                              "change": null,
                              "threshold": "Source returns data",
                              "evidence": []
                            }
                          ]
                        }
                      },
                      "limits": {
                        "rows": 25,
                        "search_console_page_size": 25
                      },
                      "ui_url": "https://analystic.dev/clients/00000000-0000-4000-8000-000000000001?preset=client-overview&range=lastMonth&compare=previous_period"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/BillingRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        }
      }
    },
    "/api/reporting/v1/reports/{report}": {
      "get": {
        "tags": [
          "Reporting"
        ],
        "summary": "The site's report (Company organizations)",
        "operationId": "companyReport",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-required-scope": "reports:read",
        "parameters": [
          {
            "$ref": "#/components/parameters/report"
          },
          {
            "$ref": "#/components/parameters/period"
          },
          {
            "$ref": "#/components/parameters/start"
          },
          {
            "$ref": "#/components/parameters/end"
          },
          {
            "$ref": "#/components/parameters/comparison"
          },
          {
            "$ref": "#/components/parameters/comparison_start"
          },
          {
            "$ref": "#/components/parameters/comparison_end"
          },
          {
            "$ref": "#/components/parameters/limit"
          }
        ],
        "responses": {
          "200": {
            "description": "The report (also when a source failed — see sources.*.status).",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Report"
                },
                "examples": {
                  "agencyOverview": {
                    "value": {
                      "schema_version": "1",
                      "api_version": "v1",
                      "report": "overview",
                      "request_id": "req_3f9a1c2b7d4e5f60a1b2",
                      "generated_at": "2026-10-05T09:30:00.000Z",
                      "organization": {
                        "id": "org_example",
                        "mode": "agency"
                      },
                      "client": {
                        "id": "00000000-0000-4000-8000-000000000001",
                        "external_key": "crm-1042",
                        "name": "Nordvik Studio AB",
                        "domain": "nordvik.example"
                      },
                      "business_model": {
                        "value": "lead_generation",
                        "complete": true
                      },
                      "period": {
                        "start": "2026-09-01",
                        "end": "2026-09-30",
                        "days": 30,
                        "preset": "last_month"
                      },
                      "comparison": {
                        "mode": "previous_period",
                        "start": "2026-08-02",
                        "end": "2026-08-31",
                        "days": 30
                      },
                      "sources": {
                        "ga4": {
                          "configured": true,
                          "loaded": true,
                          "status": "ok",
                          "resources": [
                            {
                              "id": "00000000-0000-4000-8000-0000000000a1",
                              "property_id": "123456789",
                              "name": "Nordvik Studio – GA4",
                              "status": "ok"
                            }
                          ]
                        },
                        "search_console": {
                          "configured": true,
                          "loaded": true,
                          "status": "ok",
                          "resources": [
                            {
                              "id": "00000000-0000-4000-8000-0000000000b1",
                              "site_url": "sc-domain:nordvik.example",
                              "name": "nordvik.example",
                              "status": "ok",
                              "latest_data_date": "2026-09-30"
                            }
                          ]
                        },
                        "google_ads": {
                          "configured": true,
                          "loaded": true,
                          "status": "error",
                          "resources": [
                            {
                              "id": "00000000-0000-4000-8000-0000000000c1",
                              "customer_id": "1234567890",
                              "name": "Nordvik Studio Ads",
                              "currency": "SEK",
                              "status": "quota_exceeded",
                              "error": {
                                "kind": "quota_exceeded",
                                "message": "Google Ads temporarily limited requests"
                              }
                            }
                          ]
                        }
                      },
                      "summary": {
                        "ga4": [
                          {
                            "id": "00000000-0000-4000-8000-0000000000a1",
                            "name": "Nordvik Studio – GA4",
                            "scope": "all_traffic",
                            "metrics": {
                              "sessions": {
                                "value": 1200,
                                "comparison": 1050,
                                "change": {
                                  "absolute": 150,
                                  "percent": 14.29,
                                  "direction": "up"
                                }
                              },
                              "engagement_rate": {
                                "value": 0.6125,
                                "comparison": 0.58,
                                "change": {
                                  "absolute": 0.0325,
                                  "percent": 5.6,
                                  "direction": "up"
                                }
                              },
                              "key_events": {
                                "value": 42,
                                "comparison": 0,
                                "change": {
                                  "absolute": 42,
                                  "percent": null,
                                  "direction": "new"
                                }
                              }
                            },
                            "traffic_split": {
                              "sessions": {
                                "organic": {
                                  "value": 640,
                                  "comparison": 600,
                                  "change": {
                                    "absolute": 40,
                                    "percent": 6.67,
                                    "direction": "up"
                                  }
                                }
                              }
                            }
                          }
                        ],
                        "search_console": [
                          {
                            "id": "00000000-0000-4000-8000-0000000000b1",
                            "name": "nordvik.example",
                            "metrics": {
                              "clicks": {
                                "value": 510,
                                "comparison": 480,
                                "change": {
                                  "absolute": 30,
                                  "percent": 6.25,
                                  "direction": "up"
                                }
                              },
                              "average_position": {
                                "value": 8.4,
                                "comparison": 9.1,
                                "change": {
                                  "absolute": -0.7,
                                  "percent": -7.69,
                                  "direction": "down"
                                }
                              }
                            }
                          }
                        ],
                        "google_ads": [
                          {
                            "id": "00000000-0000-4000-8000-0000000000c1",
                            "name": "Nordvik Studio Ads",
                            "currency": "SEK",
                            "metrics": null
                          }
                        ]
                      },
                      "series": {
                        "ga4": [
                          {
                            "id": "00000000-0000-4000-8000-0000000000a1",
                            "name": "Nordvik Studio – GA4",
                            "points": [
                              {
                                "date": "2026-09-01",
                                "sessions": 41,
                                "sessions_organic": 22,
                                "sessions_paid": 9,
                                "sessions_other": 10,
                                "key_events": 1,
                                "key_events_organic": 1,
                                "key_events_paid": 0,
                                "key_events_other": 0,
                                "events": 380
                              }
                            ],
                            "comparison_points": [
                              {
                                "date": "2026-08-02",
                                "sessions": 35,
                                "sessions_organic": 20,
                                "sessions_paid": 7,
                                "sessions_other": 8,
                                "key_events": 0,
                                "key_events_organic": 0,
                                "key_events_paid": 0,
                                "key_events_other": 0,
                                "events": 300
                              }
                            ]
                          }
                        ]
                      },
                      "tables": {
                        "ga4_key_events": [
                          {
                            "id": "00000000-0000-4000-8000-0000000000a1",
                            "name": "Nordvik Studio – GA4",
                            "total_rows": 1,
                            "rows": [
                              {
                                "event_name": "generate_lead",
                                "events": 44,
                                "key_events": {
                                  "value": 42,
                                  "comparison": 0,
                                  "change": {
                                    "absolute": 42,
                                    "percent": null,
                                    "direction": "new"
                                  }
                                }
                              }
                            ]
                          }
                        ]
                      },
                      "intelligence": {
                        "checks": {
                          "total": 1,
                          "items": [
                            {
                              "id": "SOURCE_UNAVAILABLE:ads:00000000-0000-4000-8000-0000000000c1",
                              "reason_code": "SOURCE_UNAVAILABLE",
                              "kind": "measurement_check",
                              "severity": "high",
                              "title": "Google Ads data unavailable",
                              "reason": "Google Ads could not be read for this period.",
                              "source": "google_ads",
                              "resource": {
                                "id": "00000000-0000-4000-8000-0000000000c1",
                                "name": "Nordvik Studio Ads"
                              },
                              "metric": "source",
                              "value_kind": "count",
                              "currency": null,
                              "current": null,
                              "comparison": null,
                              "change": null,
                              "threshold": "Source returns data",
                              "evidence": []
                            }
                          ]
                        }
                      },
                      "limits": {
                        "rows": 25,
                        "search_console_page_size": 25
                      },
                      "ui_url": "https://analystic.dev/clients/00000000-0000-4000-8000-000000000001?preset=client-overview&range=lastMonth&compare=previous_period"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/BillingRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        }
      }
    },
    "/api/reporting/v1/clients/{client}/reports/{report}/{table}": {
      "get": {
        "tags": [
          "Reporting"
        ],
        "summary": "One Search Console page of the SEO report (25 rows by clicks), with filters and a cursor",
        "operationId": "clientSeoTable",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-required-scope": "reports:read",
        "parameters": [
          {
            "$ref": "#/components/parameters/client"
          },
          {
            "name": "report",
            "in": "path",
            "required": true,
            "schema": {
              "const": "seo"
            }
          },
          {
            "name": "table",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "queries",
                "pages"
              ]
            }
          },
          {
            "$ref": "#/components/parameters/site"
          },
          {
            "$ref": "#/components/parameters/period"
          },
          {
            "$ref": "#/components/parameters/start"
          },
          {
            "$ref": "#/components/parameters/end"
          },
          {
            "$ref": "#/components/parameters/cursor"
          },
          {
            "name": "query_contains",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "description": "Filter: query contains this text (at most one filter per dimension)."
          },
          {
            "name": "query_equals",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "description": "Filter: query equals this text (at most one filter per dimension)."
          },
          {
            "name": "query_not_contains",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "description": "Filter: query not contains this text (at most one filter per dimension)."
          },
          {
            "name": "page_contains",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "description": "Filter: page contains this text (at most one filter per dimension)."
          },
          {
            "name": "page_equals",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "description": "Filter: page equals this text (at most one filter per dimension)."
          },
          {
            "name": "page_not_contains",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "description": "Filter: page not contains this text (at most one filter per dimension)."
          }
        ],
        "responses": {
          "200": {
            "description": "A page (status error = Search Console failed; rows null).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchConsolePage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/BillingRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/reporting/v1/reports/{report}/{table}": {
      "get": {
        "tags": [
          "Reporting"
        ],
        "summary": "One Search Console page of the SEO report (25 rows by clicks), with filters and a cursor",
        "operationId": "companySeoTable",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-required-scope": "reports:read",
        "parameters": [
          {
            "name": "report",
            "in": "path",
            "required": true,
            "schema": {
              "const": "seo"
            }
          },
          {
            "name": "table",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "queries",
                "pages"
              ]
            }
          },
          {
            "$ref": "#/components/parameters/site"
          },
          {
            "$ref": "#/components/parameters/period"
          },
          {
            "$ref": "#/components/parameters/start"
          },
          {
            "$ref": "#/components/parameters/end"
          },
          {
            "$ref": "#/components/parameters/cursor"
          },
          {
            "name": "query_contains",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "description": "Filter: query contains this text (at most one filter per dimension)."
          },
          {
            "name": "query_equals",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "description": "Filter: query equals this text (at most one filter per dimension)."
          },
          {
            "name": "query_not_contains",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "description": "Filter: query not contains this text (at most one filter per dimension)."
          },
          {
            "name": "page_contains",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "description": "Filter: page contains this text (at most one filter per dimension)."
          },
          {
            "name": "page_equals",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "description": "Filter: page equals this text (at most one filter per dimension)."
          },
          {
            "name": "page_not_contains",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "description": "Filter: page not contains this text (at most one filter per dimension)."
          }
        ],
        "responses": {
          "200": {
            "description": "A page (status error = Search Console failed; rows null).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchConsolePage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/BillingRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/automation/v1/organization": {
      "get": {
        "tags": [
          "Automation"
        ],
        "summary": "Organization metadata",
        "operationId": "organization",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-required-scope": "organization:read",
        "responses": {
          "200": {
            "description": "Organization",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/BillingRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/automation/v1/clients": {
      "get": {
        "tags": [
          "Automation"
        ],
        "summary": "List clients (page, limit ≤ 100) or look one up by external_key",
        "operationId": "listClients",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-required-scope": "clients:read",
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "external_key",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Clients",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/BillingRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "tags": [
          "Automation"
        ],
        "summary": "Create or update one client by external_key (Agency)",
        "operationId": "upsertClient",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-required-scope": "clients:write",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClientInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated or unchanged"
          },
          "201": {
            "description": "Created"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/BillingRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "422": {
            "$ref": "#/components/responses/ValidationFailed"
          }
        }
      }
    },
    "/api/automation/v1/clients/{id}": {
      "get": {
        "tags": [
          "Automation"
        ],
        "summary": "One client by Analystic id",
        "operationId": "getClient",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-required-scope": "clients:read",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Client"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/BillingRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/automation/v1/clients/bulk": {
      "post": {
        "tags": [
          "Automation"
        ],
        "summary": "Up to 500 clients, all or nothing: upsert, or full sync (confirm_full_sync: true)",
        "operationId": "bulkClients",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-required-scope": "clients:write",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "clients"
                ],
                "properties": {
                  "mode": {
                    "enum": [
                      "upsert",
                      "sync"
                    ]
                  },
                  "confirm_full_sync": {
                    "type": "boolean"
                  },
                  "clients": {
                    "type": "array",
                    "maxItems": 500,
                    "items": {
                      "$ref": "#/components/schemas/ClientInput"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Summary"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/BillingRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "413": {
            "$ref": "#/components/responses/BadRequest"
          },
          "422": {
            "$ref": "#/components/responses/ValidationFailed"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "An Analystic organization token (Analystic → Automations). Scopes: clients:read, clients:write, organization:read, reports:read."
      }
    },
    "parameters": {
      "client": {
        "name": "client",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        },
        "description": "The client's external_key (canonical) or Analystic id, within the token's organization."
      },
      "report": {
        "name": "report",
        "in": "path",
        "required": true,
        "schema": {
          "enum": [
            "overview",
            "seo",
            "paid-search",
            "lead-generation",
            "ecommerce"
          ]
        }
      },
      "period": {
        "name": "period",
        "in": "query",
        "schema": {
          "enum": [
            "last7",
            "last28",
            "last30",
            "this_month",
            "last_month"
          ],
          "default": "last30"
        },
        "description": "Not together with start/end."
      },
      "start": {
        "name": "start",
        "in": "query",
        "schema": {
          "type": "string",
          "format": "date"
        },
        "description": "Custom period start (with end; at most 366 days; not in the future)."
      },
      "end": {
        "name": "end",
        "in": "query",
        "schema": {
          "type": "string",
          "format": "date"
        }
      },
      "comparison": {
        "name": "comparison",
        "in": "query",
        "schema": {
          "enum": [
            "none",
            "previous_period",
            "mom",
            "yoy",
            "custom"
          ],
          "default": "none"
        },
        "description": "mom only for a period within one calendar month."
      },
      "comparison_start": {
        "name": "comparison_start",
        "in": "query",
        "schema": {
          "type": "string",
          "format": "date"
        },
        "description": "comparison=custom only."
      },
      "comparison_end": {
        "name": "comparison_end",
        "in": "query",
        "schema": {
          "type": "string",
          "format": "date"
        }
      },
      "limit": {
        "name": "limit",
        "in": "query",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "default": 25
        },
        "description": "Rows per table / list. Search Console tables and campaigns hold at most the 25 rows the report loads."
      },
      "site": {
        "name": "site",
        "in": "query",
        "schema": {
          "type": "string",
          "format": "uuid"
        },
        "description": "A Search Console site id from sources.search_console.resources (first page only)."
      },
      "cursor": {
        "name": "cursor",
        "in": "query",
        "schema": {
          "type": "string"
        },
        "description": "next_cursor from a previous response — send it alone."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "request_id": {
                "type": "string",
                "description": "Correlation id (req_ + 20 hex), equal to the X-Request-Id response header. On every Reporting API and Automation API error. Quote it when contacting support."
              },
              "details": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "Change": {
        "type": "object",
        "required": [
          "absolute",
          "percent",
          "direction"
        ],
        "properties": {
          "absolute": {
            "type": "number",
            "description": "value − comparison (rates: ratio points)."
          },
          "percent": {
            "type": [
              "number",
              "null"
            ],
            "description": "Relative change in percent; null with a zero baseline."
          },
          "direction": {
            "enum": [
              "up",
              "down",
              "unchanged",
              "new"
            ]
          }
        }
      },
      "Metric": {
        "type": "object",
        "description": "A metric. `value` null = not available (never a disguised zero). With a comparison: `comparison` and `change` (null when the comparison value is unavailable).",
        "required": [
          "value"
        ],
        "properties": {
          "value": {
            "type": [
              "number",
              "null"
            ]
          },
          "currency": {
            "type": [
              "string",
              "null"
            ],
            "description": "ISO 4217 — present on money metrics only."
          },
          "comparison": {
            "type": [
              "number",
              "null"
            ]
          },
          "change": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Change"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "SourceBlock": {
        "type": "object",
        "required": [
          "configured",
          "loaded",
          "status",
          "resources"
        ],
        "properties": {
          "configured": {
            "type": "boolean"
          },
          "loaded": {
            "type": "boolean",
            "description": "false when this report does not read the source (status not_loaded)."
          },
          "status": {
            "enum": [
              "ok",
              "partial",
              "not_configured",
              "not_loaded",
              "unavailable",
              "error"
            ]
          },
          "resources": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "name",
                "status"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "status": {
                  "enum": [
                    "ok",
                    "not_loaded",
                    "quota_exceeded",
                    "reauth_required",
                    "not_accessible",
                    "not_configured",
                    "unavailable",
                    "error"
                  ]
                },
                "error": {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                },
                "latest_data_date": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date"
                },
                "currency": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          }
        }
      },
      "Report": {
        "type": "object",
        "required": [
          "schema_version",
          "api_version",
          "report",
          "request_id",
          "generated_at",
          "organization",
          "business_model",
          "period",
          "comparison",
          "sources",
          "summary",
          "series",
          "tables",
          "intelligence",
          "ui_url"
        ],
        "properties": {
          "schema_version": {
            "const": "1"
          },
          "api_version": {
            "const": "v1"
          },
          "report": {
            "enum": [
              "overview",
              "seo",
              "paid-search",
              "lead-generation",
              "ecommerce"
            ]
          },
          "request_id": {
            "type": "string"
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "organization": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "mode": {
                "enum": [
                  "agency",
                  "company"
                ]
              }
            }
          },
          "client": {
            "type": "object",
            "description": "Agency organizations.",
            "properties": {
              "id": {
                "type": "string"
              },
              "external_key": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "domain": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "site": {
            "type": "object",
            "description": "Company organizations (no external key).",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "domain": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "business_model": {
            "type": "object",
            "properties": {
              "value": {
                "enum": [
                  "lead_generation",
                  "ecommerce",
                  "both",
                  "not_determined"
                ]
              },
              "complete": {
                "type": "boolean"
              }
            }
          },
          "period": {
            "type": "object",
            "properties": {
              "start": {
                "type": "string",
                "format": "date"
              },
              "end": {
                "type": "string",
                "format": "date"
              },
              "days": {
                "type": "integer"
              },
              "preset": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "comparison": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "properties": {
                  "mode": {
                    "enum": [
                      "previous_period",
                      "mom",
                      "yoy",
                      "custom"
                    ]
                  },
                  "start": {
                    "type": "string",
                    "format": "date"
                  },
                  "end": {
                    "type": "string",
                    "format": "date"
                  },
                  "days": {
                    "type": "integer"
                  }
                }
              }
            ]
          },
          "sources": {
            "type": "object",
            "properties": {
              "ga4": {
                "$ref": "#/components/schemas/SourceBlock"
              },
              "search_console": {
                "$ref": "#/components/schemas/SourceBlock"
              },
              "google_ads": {
                "$ref": "#/components/schemas/SourceBlock"
              }
            }
          },
          "summary": {
            "type": "object",
            "description": "Per source, one entry per resource: { id, name, metrics } (metrics null = unavailable). GA4 entries carry scope (all_traffic | organic_search | paid_search) and, by report, traffic_split / outcome_split / ecommerce; Google Ads entries carry currency.",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  },
                  "metrics": {
                    "oneOf": [
                      {
                        "type": "null"
                      },
                      {
                        "type": "object",
                        "additionalProperties": {
                          "$ref": "#/components/schemas/Metric"
                        }
                      }
                    ]
                  }
                }
              }
            }
          },
          "series": {
            "type": "object",
            "description": "Per source, per resource: points (the period's days) and comparison_points (the comparison period's own dates)."
          },
          "tables": {
            "type": "object",
            "description": "ga4_key_events, google_ads_campaigns (by spend), search_console (queries / pages by clicks, with next_cursor), ga4_organic_landing_pages — by report."
          },
          "intelligence": {
            "type": "object",
            "description": "checks (measurement checks / performance changes), seo (SEO report insights), ai_referrals (sessions from AI assistants — not AI Overview impressions)."
          },
          "limits": {
            "type": "object"
          },
          "ui_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "SearchConsolePage": {
        "type": "object",
        "properties": {
          "table": {
            "enum": [
              "queries",
              "pages"
            ]
          },
          "site": {
            "type": "string"
          },
          "status": {
            "enum": [
              "ok",
              "error"
            ]
          },
          "rows": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "object",
              "properties": {
                "query": {
                  "type": "string"
                },
                "page": {
                  "type": "string"
                },
                "clicks": {
                  "type": "number"
                },
                "impressions": {
                  "type": "number"
                },
                "ctr": {
                  "type": "number"
                },
                "average_position": {
                  "type": "number"
                }
              }
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ClientInput": {
        "type": "object",
        "required": [
          "external_key"
        ],
        "additionalProperties": false,
        "properties": {
          "external_key": {
            "type": "string",
            "maxLength": 200
          },
          "name": {
            "type": "string"
          },
          "domain": {
            "type": [
              "string",
              "null"
            ]
          },
          "active": {
            "type": "boolean"
          },
          "ga4_property_ids": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "search_console_sites": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "google_ads_customer_ids": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "validation_error / invalid_period / invalid_comparison / invalid_cursor",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "unauthorized / invalid_token",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "BillingRequired": {
        "description": "billing_required",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "invalid_scope / organization_not_allowed",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "client_not_found / site_not_found / report_not_supported",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Conflict": {
        "description": "client_required / company_mode_not_supported / company_not_configured / company_configuration_inactive",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "rate_limited / too_many_concurrent_requests (Retry-After)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "ValidationFailed": {
        "description": "validation_error with details",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Timeout": {
        "description": "report_timeout",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}
