{
  "swagger": "2.0",
  "info": {
    "title": "Document.com Proposals",
    "version": "1.0.0",
    "description": "Generate offers, follow their status and download accepted quote PDFs with a key scoped to one master template revision."
  },
  "host": "app.document.com",
  "basePath": "/api/v1/proposals",
  "schemes": [
    "https"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "securityDefinitions": {
    "TemplateKey": {
      "type": "apiKey",
      "name": "Authorization",
      "in": "header",
      "description": "Enter Bearer, a space, and your Document.com template key."
    }
  },
  "security": [
    {
      "TemplateKey": []
    }
  ],
  "paths": {
    "/generate": {
      "post": {
        "operationId": "CreateOffer",
        "summary": "Create a proposal",
        "description": "Creates an offer without sending it. Save the request UUID with your source record and use the same UUID and body when retrying.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "One UUID for this offer. Keep it across retries.",
            "type": "string",
            "format": "uuid"
          },
          {
            "name": "buyer",
            "in": "body",
            "required": true,
            "description": "Buyer details and template inputs.",
            "schema": {
              "$ref": "#/definitions/Buyer"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Create a proposal",
            "schema": {
              "$ref": "#/definitions/CreatedOffer"
            }
          },
          "400": {
            "description": "Invalid parameters."
          },
          "401": {
            "description": "Invalid or revoked template key."
          },
          "403": {
            "description": "An active workspace is required."
          },
          "402": {
            "description": "Workspace storage limit reached."
          },
          "409": {
            "description": "Request UUID already used for a different offer."
          },
          "429": {
            "description": "Retry later."
          }
        }
      }
    },
    "/events": {
      "get": {
        "operationId": "ListOfferEvents",
        "summary": "List proposal events",
        "description": "Store nextCursor after processing a page. Use each event ID to avoid repeating actions. Follow hasMore for additional pages.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "",
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "default": 25
          },
          {
            "name": "after",
            "in": "query",
            "required": false,
            "description": "The cursor returned by the preceding page.",
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "List proposal events",
            "schema": {
              "$ref": "#/definitions/EventPage"
            }
          },
          "400": {
            "description": "Invalid parameters."
          },
          "401": {
            "description": "Invalid or revoked template key."
          },
          "403": {
            "description": "An active workspace is required."
          },
          "429": {
            "description": "Retry later."
          }
        }
      }
    },
    "/{id}": {
      "get": {
        "operationId": "GetOfferStatus",
        "summary": "Get proposal status",
        "description": "Reads an offer created by this template revision.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID of an offer created from this template revision.",
            "type": "string",
            "format": "uuid"
          }
        ],
        "responses": {
          "200": {
            "description": "Get proposal status",
            "schema": {
              "$ref": "#/definitions/OfferStatus"
            }
          },
          "400": {
            "description": "Invalid parameters."
          },
          "401": {
            "description": "Invalid or revoked template key."
          },
          "403": {
            "description": "An active workspace is required."
          },
          "404": {
            "description": "Offer unavailable to this key."
          }
        }
      }
    },
    "/{id}/pdf": {
      "get": {
        "operationId": "DownloadAcceptedOffer",
        "summary": "Download accepted quote PDF",
        "description": "Download the accepted proposal. A separately executed signature envelope has its own completed files.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID of an offer created from this template revision.",
            "type": "string",
            "format": "uuid"
          }
        ],
        "responses": {
          "200": {
            "description": "Download accepted quote PDF",
            "schema": {
              "type": "file"
            }
          },
          "400": {
            "description": "Invalid parameters."
          },
          "401": {
            "description": "Invalid or revoked template key."
          },
          "403": {
            "description": "An active workspace is required."
          },
          "404": {
            "description": "Offer unavailable to this key."
          },
          "409": {
            "description": "This offer has no available accepted PDF."
          },
          "429": {
            "description": "Retry later."
          }
        },
        "produces": [
          "application/pdf"
        ]
      }
    }
  },
  "definitions": {
    "VolumeTier": {
      "type": "object",
      "properties": {
        "from": {
          "type": "integer",
          "minimum": 2,
          "maximum": 500
        },
        "cents": {
          "type": "integer",
          "minimum": 0,
          "maximum": 50000000
        }
      },
      "required": [
        "from",
        "cents"
      ]
    },
    "Billing": {
      "type": "object",
      "properties": {
        "interval": {
          "type": "string",
          "enum": [
            "month",
            "year"
          ]
        },
        "payments": {
          "type": "integer",
          "minimum": 1,
          "maximum": 120,
          "x-nullable": true
        }
      },
      "required": [
        "interval",
        "payments"
      ]
    },
    "PriceLine": {
      "type": "object",
      "properties": {
        "label": {
          "type": "string",
          "maxLength": 160,
          "minLength": 1
        },
        "cents": {
          "type": "integer",
          "minimum": 0,
          "maximum": 50000000
        },
        "description": {
          "type": "string",
          "maxLength": 500
        },
        "terms": {
          "type": "string",
          "maxLength": 2200
        },
        "discountBps": {
          "type": "integer",
          "minimum": 0,
          "maximum": 10000
        },
        "initialUnits": {
          "type": "integer",
          "minimum": 1,
          "maximum": 500
        },
        "maxUnits": {
          "type": "integer",
          "minimum": 1,
          "maximum": 500
        },
        "volumeTiers": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/VolumeTier"
          },
          "minItems": 1,
          "maxItems": 8
        },
        "volumePrice": {
          "$ref": "#/definitions/VolumeTier"
        },
        "billing": {
          "$ref": "#/definitions/Billing"
        }
      },
      "required": [
        "label",
        "cents"
      ]
    },
    "Buyer": {
      "type": "object",
      "properties": {
        "clientName": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "clientEmail": {
          "type": "string",
          "format": "email",
          "maxLength": 255
        },
        "variables": {
          "type": "object",
          "maxProperties": 50,
          "additionalProperties": {
            "type": "string",
            "maxLength": 2200
          },
          "description": "Merge variables for the selected revision. For {{data.dealName}}, supply dealName."
        },
        "additionalItems": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/PriceLine"
          },
          "maxItems": 20
        }
      },
      "required": [
        "clientName",
        "clientEmail"
      ],
      "additionalProperties": false
    },
    "CreatedOffer": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "recipientUrl": {
          "type": "string",
          "format": "uri",
          "description": "Private buyer URL. Anyone with this URL can accept the proposal."
        },
        "revision": {
          "type": "integer"
        },
        "workspacePath": {
          "type": "string"
        },
        "statusPath": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "revision",
        "recipientUrl",
        "workspacePath",
        "statusPath"
      ]
    },
    "OfferStatus": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "title": {
          "type": "string"
        },
        "openedAt": {
          "type": "string",
          "format": "date-time",
          "x-nullable": true
        },
        "acceptedAt": {
          "type": "string",
          "format": "date-time",
          "x-nullable": true
        },
        "invoicedAt": {
          "type": "string",
          "format": "date-time",
          "x-nullable": true
        },
        "withdrawnAt": {
          "type": "string",
          "format": "date-time",
          "x-nullable": true
        },
        "expiresAt": {
          "type": "string",
          "format": "date-time"
        },
        "recipientDownloads": {
          "type": "integer"
        },
        "lastDownloadedAt": {
          "type": "string",
          "format": "date-time",
          "x-nullable": true
        },
        "pdfPath": {
          "type": "string",
          "x-nullable": true
        }
      },
      "required": [
        "id",
        "title",
        "expiresAt"
      ]
    },
    "OfferEvent": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "Stable event ID for deduplication."
        },
        "type": {
          "type": "string",
          "enum": [
            "created",
            "opened",
            "accepted",
            "withdrawn",
            "invoiced"
          ]
        },
        "proposalId": {
          "type": "string",
          "format": "uuid"
        },
        "occurredAt": {
          "type": "string",
          "format": "date-time"
        },
        "statusPath": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "type",
        "proposalId",
        "occurredAt",
        "statusPath"
      ]
    },
    "EventPage": {
      "type": "object",
      "properties": {
        "events": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/OfferEvent"
          }
        },
        "nextCursor": {
          "type": "string",
          "x-nullable": true
        },
        "hasMore": {
          "type": "boolean"
        }
      },
      "required": [
        "events",
        "hasMore",
        "nextCursor"
      ]
    }
  }
}
