{
  "openapi": "3.1.0",
  "info": {
    "title": "Pagecuts",
    "version": "1.0.0",
    "summary": "A 15-second video ad kit from a business's web page.",
    "description": "Every ad is made for a person whose email address has been confirmed with a code: sendCode emails it, makeAd starts the build with it, getAd follows it. No API key. A build takes about five minutes; the preview is free and marked; the kit is US$19 once, paid by a person at checkout. Reference: https://pagecuts.com/docs.md"
  },
  "servers": [
    {
      "url": "https://pagecuts.com"
    }
  ],
  "paths": {
    "/api/codes": {
      "post": {
        "operationId": "sendCode",
        "summary": "Email a person the code that confirms their address. Ask them for it, then call makeAd.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "The person's own email address."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The code is on its way.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "sent": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/requests": {
      "post": {
        "operationId": "makeAd",
        "summary": "Start building an ad kit from a web page, for the person whose code this is.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "The page the ad should send people to. A bare domain is fine."
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "The address sendCode was called with. Not needed with a signed-in person's bearer token."
                  },
                  "code": {
                    "type": "string",
                    "description": "The code that address was emailed. It works once, for an hour."
                  },
                  "instructions": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Optional. What this ad should push and who it is for."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The build is queued.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "id",
                    "page",
                    "status"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "page": {
                      "type": "string",
                      "format": "uri",
                      "description": "For a person: the build live, then the preview and the checkout."
                    },
                    "status": {
                      "type": "string",
                      "format": "uri",
                      "description": "The address of getAd for this ad."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/requests/{id}": {
      "get": {
        "operationId": "getAd",
        "summary": "The state of an ad: progress, then the preview, then the kit once paid.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "wait",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0,
              "maximum": 25
            },
            "description": "Seconds to hold the call until there is a preview or the build has failed."
          }
        ],
        "responses": {
          "200": {
            "description": "The ad.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ad"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/requests/{id}/checkout": {
      "get": {
        "operationId": "checkout",
        "summary": "For a person in a browser: redirects to the payment page for this ad's kit.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "303": {
            "description": "To Stripe Checkout, or back to the ad's page if there is nothing to pay yet or it is already paid."
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "Error": {
        "description": "A refusal.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": [
                "error"
              ],
              "properties": {
                "error": {
                  "type": "string",
                  "enum": [
                    "invalid_url",
                    "private",
                    "not_found",
                    "rate_limited",
                    "busy",
                    "server"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "Ad": {
        "type": "object",
        "required": [
          "id",
          "page",
          "host",
          "status",
          "paid",
          "progress",
          "stills"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "page": {
            "type": "string",
            "format": "uri"
          },
          "host": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "preview_ready",
              "done",
              "failed"
            ]
          },
          "paid": {
            "type": "boolean"
          },
          "progress": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "step": {
                  "type": "string"
                },
                "stage": {
                  "type": "integer",
                  "description": "1 research, 2 design, 3 rendering, 4 preview ready."
                },
                "at": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "started_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "finished_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When the preview was ready, or the build failed."
          },
          "server_now": {
            "type": "string",
            "format": "date-time"
          },
          "preview": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "The marked preview, MP4, 720x900."
          },
          "cover": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "The preview's opening frame, a marked JPEG."
          },
          "stills": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "description": "Two marked JPEG stills."
          },
          "sample": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "primary": {
                "type": "string"
              },
              "headline": {
                "type": "string"
              }
            }
          },
          "checkout": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Where a person pays for the kit. Null before the preview and after payment."
          },
          "kit": {
            "type": [
              "object",
              "null"
            ],
            "description": "Present once the ad is paid for and status is done.",
            "properties": {
              "zip": {
                "type": "string",
                "format": "uri"
              },
              "copy_file": {
                "type": "string",
                "format": "uri"
              },
              "copy": {
                "type": "object",
                "properties": {
                  "primary_texts": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "headlines": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "descriptions": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "button": {
                    "type": "string"
                  }
                }
              },
              "videos": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "label": {
                      "type": "string"
                    },
                    "url": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                }
              },
              "stills": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "label": {
                      "type": "string"
                    },
                    "url": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                }
              }
            }
          },
          "more": {
            "type": [
              "object",
              "null"
            ],
            "description": "The rest of the kit, made in the minutes after it is paid for: null before payment, then { status: queued | running | failed }, then status done with videos (16:9 and a six-second cut), stills (landscape and 2:3), copy for Google, Pinterest, LinkedIn, TikTok and Snapchat, and copy_file. See docs.md.",
            "properties": {
              "status": {
                "type": "string",
                "enum": [
                  "queued",
                  "running",
                  "done",
                  "failed"
                ]
              }
            }
          }
        }
      }
    }
  }
}
