{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/rewalto-com/json-schema/rewalto-com-report-schedule-create-schema.json",
  "title": "Create a schedule",
  "description": "A draft schedule; it runs nothing until its cost is confirmed with activate.",
  "x-generated": "2026-11-23",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/rewalto-com-openapi.json#/components/schemas/ReportScheduleCreate",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "idempotencyKey",
    "name",
    "data",
    "window",
    "frequency",
    "timezone",
    "renderer",
    "title",
    "subject",
    "delivery",
    "spendingLimit"
  ],
  "properties": {
    "idempotencyKey": {
      "type": "string",
      "title": "Idempotency key",
      "description": "Chosen once by the caller for this action and repeated unchanged on every retry. The same key and body return the first answer; the same key with a different body is refused (idempotency_conflict).",
      "pattern": "^[A-Za-z0-9._:-]{8,128}$"
    },
    "name": {
      "type": "string",
      "title": "Name",
      "description": "A name for the schedule.",
      "minLength": 1,
      "maxLength": 200
    },
    "data": {
      "type": "object",
      "title": "Data",
      "description": "What each delivery reads: the report data request without its period (the window rule gives it).",
      "additionalProperties": false,
      "required": [
        "datasets"
      ],
      "properties": {
        "datasets": {
          "type": "array",
          "items": {
            "type": "object",
            "title": "Dataset request",
            "description": "One dataset, narrowed.",
            "additionalProperties": false,
            "required": [
              "dataset"
            ],
            "properties": {
              "dataset": {
                "type": "string",
                "enum": [
                  "listings",
                  "observations",
                  "rating_changes",
                  "banner_placements",
                  "brand_mentions",
                  "promo_emails",
                  "storefront_promos",
                  "ad_creatives",
                  "brands",
                  "retailers"
                ],
                "title": "Dataset",
                "description": "Which dataset."
              },
              "fields": {
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-zA-Z][a-zA-Z0-9_]{0,60}$"
                },
                "title": "Fields",
                "description": "Only these fields of each record (the record id and its source fields are always included). Default: all.",
                "maxItems": 100,
                "uniqueItems": true
              },
              "filters": {
                "type": "object",
                "title": "Report data filters",
                "description": "Narrow a dataset. Values are exact (brands as retailers write them). Each dataset supports only some filters.",
                "additionalProperties": false,
                "required": [],
                "properties": {
                  "retailers": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 200,
                      "pattern": "^[a-z0-9_]{1,40}$"
                    },
                    "title": "Retailers",
                    "description": "Retailer ids.",
                    "minItems": 1,
                    "maxItems": 200,
                    "uniqueItems": true
                  },
                  "brands": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 200
                    },
                    "title": "Brands",
                    "description": "Brands, exactly as written.",
                    "minItems": 1,
                    "maxItems": 200,
                    "uniqueItems": true
                  },
                  "pincodes": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 200,
                      "pattern": "^[1-9][0-9]{5}$"
                    },
                    "title": "Pin codes",
                    "description": "Six-digit pin codes.",
                    "minItems": 1,
                    "maxItems": 200,
                    "uniqueItems": true
                  },
                  "productIds": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 200,
                      "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
                    },
                    "title": "Products",
                    "description": "Core product ids.",
                    "minItems": 1,
                    "maxItems": 200,
                    "uniqueItems": true
                  },
                  "retailerSkus": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 200
                    },
                    "title": "Retailer SKUs",
                    "description": "Retailers' own product ids.",
                    "minItems": 1,
                    "maxItems": 200,
                    "uniqueItems": true
                  },
                  "searchTerms": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 200
                    },
                    "title": "Search terms",
                    "description": "Search terms, as typed in the app.",
                    "minItems": 1,
                    "maxItems": 200,
                    "uniqueItems": true
                  },
                  "advertisers": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 200
                    },
                    "title": "Advertisers",
                    "description": "Advertiser names, as the ad library shows them.",
                    "minItems": 1,
                    "maxItems": 200,
                    "uniqueItems": true
                  },
                  "domains": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 200
                    },
                    "title": "Domains",
                    "description": "Brands' own store domains.",
                    "minItems": 1,
                    "maxItems": 200,
                    "uniqueItems": true
                  }
                }
              }
            }
          },
          "title": "Datasets",
          "description": "One entry per dataset; each dataset at most once.",
          "minItems": 1,
          "maxItems": 10
        }
      }
    },
    "window": {
      "title": "Reporting window",
      "description": "Which days each delivery covers, in the schedule time zone: the last N complete days before the run, or the previous calendar week or month.",
      "oneOf": [
        {
          "type": "object",
          "title": "Rolling days",
          "description": "The last N complete days.",
          "additionalProperties": false,
          "required": [
            "kind",
            "days"
          ],
          "properties": {
            "kind": {
              "type": "string",
              "const": "rolling_days",
              "title": "Kind",
              "description": "rolling_days."
            },
            "days": {
              "type": "integer",
              "minimum": 1,
              "title": "Days",
              "description": "1 to 366.",
              "maximum": 366
            }
          }
        },
        {
          "type": "object",
          "title": "Previous calendar period",
          "description": "The previous complete week (Monday to Sunday) or month.",
          "additionalProperties": false,
          "required": [
            "kind",
            "period"
          ],
          "properties": {
            "kind": {
              "type": "string",
              "const": "previous_period",
              "title": "Kind",
              "description": "previous_period."
            },
            "period": {
              "type": "string",
              "enum": [
                "week",
                "month"
              ],
              "title": "Period",
              "description": "week or month."
            }
          }
        }
      ]
    },
    "frequency": {
      "title": "Frequency",
      "description": "When deliveries run, in the schedule time zone.",
      "oneOf": [
        {
          "type": "object",
          "title": "Daily",
          "description": "Every day.",
          "additionalProperties": false,
          "required": [
            "kind",
            "time"
          ],
          "properties": {
            "kind": {
              "type": "string",
              "const": "daily",
              "title": "Kind",
              "description": "daily."
            },
            "time": {
              "type": "string",
              "title": "Time",
              "description": "Local time, HH:MM, 24-hour.",
              "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$"
            }
          }
        },
        {
          "type": "object",
          "title": "Weekly",
          "description": "Once a week.",
          "additionalProperties": false,
          "required": [
            "kind",
            "weekday",
            "time"
          ],
          "properties": {
            "kind": {
              "type": "string",
              "const": "weekly",
              "title": "Kind",
              "description": "weekly."
            },
            "weekday": {
              "type": "string",
              "enum": [
                "monday",
                "tuesday",
                "wednesday",
                "thursday",
                "friday",
                "saturday",
                "sunday"
              ],
              "title": "Weekday",
              "description": "The day."
            },
            "time": {
              "type": "string",
              "title": "Time",
              "description": "Local time, HH:MM, 24-hour.",
              "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$"
            }
          }
        },
        {
          "type": "object",
          "title": "Monthly",
          "description": "Once a month.",
          "additionalProperties": false,
          "required": [
            "kind",
            "dayOfMonth",
            "time"
          ],
          "properties": {
            "kind": {
              "type": "string",
              "const": "monthly",
              "title": "Kind",
              "description": "monthly."
            },
            "dayOfMonth": {
              "type": "integer",
              "minimum": 1,
              "title": "Day",
              "description": "1 to 28, so every month has it.",
              "maximum": 28
            },
            "time": {
              "type": "string",
              "title": "Time",
              "description": "Local time, HH:MM, 24-hour.",
              "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$"
            }
          }
        }
      ]
    },
    "timezone": {
      "type": "string",
      "enum": [
        "Asia/Kolkata"
      ],
      "title": "Time zone",
      "description": "Asia/Kolkata for now."
    },
    "renderer": {
      "type": "object",
      "title": "Renderer",
      "description": "The frontend's renderer the worker runs (D-1777): an allow-listed package, an exact version and a template.",
      "additionalProperties": false,
      "required": [
        "package",
        "version",
        "template"
      ],
      "properties": {
        "package": {
          "type": "string",
          "title": "Package",
          "description": "The npm package the frontend published.",
          "pattern": "^(@[a-z0-9-]+/)?[a-z0-9][a-z0-9._-]*$"
        },
        "version": {
          "type": "string",
          "title": "Version",
          "description": "An exact version on Core's allow-list (no ranges).",
          "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+(-[0-9A-Za-z.-]+)?$"
        },
        "template": {
          "type": "string",
          "title": "Template",
          "description": "A template the package declares.",
          "pattern": "^[a-z0-9][a-z0-9-]{0,60}$"
        }
      }
    },
    "title": {
      "type": "string",
      "title": "Report title",
      "description": "Each edition's title; {from} and {to} are replaced by the window dates.",
      "minLength": 1,
      "maxLength": 300
    },
    "subject": {
      "type": "object",
      "title": "Subject",
      "description": "What the report is about.",
      "additionalProperties": false,
      "required": [
        "kind",
        "name",
        "slug"
      ],
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "brand",
            "category",
            "retailer",
            "dataset"
          ],
          "title": "Kind",
          "description": "brand, category, retailer or dataset."
        },
        "name": {
          "type": "string",
          "title": "Name",
          "description": "As the report names it.",
          "minLength": 1,
          "maxLength": 200
        },
        "slug": {
          "type": "string",
          "title": "Slug",
          "description": "Lowercase words joined by hyphens.",
          "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
          "maxLength": 80
        }
      }
    },
    "delivery": {
      "type": "object",
      "title": "Delivery",
      "description": "Every edition is saved to the organisation's report history; optionally, named members are told when it is ready (a link to the report, never the file).",
      "additionalProperties": false,
      "required": [
        "saveToHistory"
      ],
      "properties": {
        "saveToHistory": {
          "type": "boolean",
          "const": true,
          "title": "Save to history",
          "description": "Always true."
        },
        "notifyUserIds": {
          "type": "array",
          "items": {
            "type": "string",
            "title": "Member",
            "description": "A member of the organisation (Clerk user id)."
          },
          "title": "Notify",
          "description": "Members told when an edition is saved or a run fails.",
          "maxItems": 20,
          "uniqueItems": true
        }
      }
    },
    "spendingLimit": {
      "type": "object",
      "title": "Spending limit",
      "description": "A run that would exceed either limit is skipped (spending_limit) and the schedule pauses.",
      "additionalProperties": false,
      "required": [
        "perDeliveryCredits",
        "perMonthCredits"
      ],
      "properties": {
        "perDeliveryCredits": {
          "type": "integer",
          "minimum": 1,
          "title": "Per delivery",
          "description": "At most this many credits per delivery."
        },
        "perMonthCredits": {
          "type": "integer",
          "minimum": 1,
          "title": "Per month",
          "description": "At most this many credits per calendar month (IST)."
        }
      }
    }
  }
}