{
 "openapi": "3.1.0",
 "info": {
  "title": "pechatnaknigi.com — book printing API",
  "version": "1.0.0",
  "description": "Price, order and track printed books in Bulgaria (Печатница НИМА, delivery to BoxNow lockers). Prices in EUR incl. 20% VAT. No API key. The customer always pays by card on the returned pay_url. Guide: https://pechatnaknigi.com/llms.txt · MCP server: https://pechatnaknigi.com/mcp"
 },
 "servers": [
  {
   "url": "https://pechatnaknigi.com"
  }
 ],
 "paths": {
  "/api/options": {
   "get": {
    "operationId": "getOptions",
    "summary": "All print options with ids, page ranges, discounts, shipping",
    "responses": {
     "200": {
      "description": "Options",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     }
    }
   }
  },
  "/api/quote": {
   "get": {
    "operationId": "quoteBook",
    "summary": "Price of one book",
    "parameters": [
     {
      "name": "pages",
      "in": "query",
      "required": true,
      "description": "Number of pages",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "quantity",
      "in": "query",
      "required": false,
      "description": "Copies",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "color_pages",
      "in": "query",
      "required": false,
      "description": "Colour pages",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "format_id",
      "in": "query",
      "required": false,
      "description": "Format",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "binding_id",
      "in": "query",
      "required": false,
      "description": "Binding",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "body_paper_id",
      "in": "query",
      "required": false,
      "description": "Inner paper",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "body_finish",
      "in": "query",
      "required": false,
      "description": "mat or gloss (premium paper)",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "cover_paper_id",
      "in": "query",
      "required": false,
      "description": "Cover paper",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "cover_color_id",
      "in": "query",
      "required": false,
      "description": "Cover print",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "lamination_id",
      "in": "query",
      "required": false,
      "description": "Lamination",
      "schema": {
       "type": "integer"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Quote",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Quote"
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "operationId": "quoteCart",
    "summary": "Price of several books in one order (shipping once)",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "books"
        ],
        "properties": {
         "books": {
          "type": "array",
          "maxItems": 10,
          "items": {
           "$ref": "#/components/schemas/Book"
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Quote",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Quote"
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/api/lockers": {
   "get": {
    "operationId": "findLockers",
    "summary": "BoxNow lockers by text or coordinates",
    "parameters": [
     {
      "name": "q",
      "in": "query",
      "required": false,
      "description": "City, district, street or shop",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "lat",
      "in": "query",
      "required": false,
      "description": "Latitude",
      "schema": {
       "type": "number"
      }
     },
     {
      "name": "lng",
      "in": "query",
      "required": false,
      "description": "Longitude",
      "schema": {
       "type": "number"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Lockers",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "lockers": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "id": {
              "type": "string"
             },
             "title": {
              "type": "string"
             },
             "address": {
              "type": "string"
             },
             "city": {
              "type": "string"
             },
             "postal": {
              "type": "string"
             },
             "distance": {
              "type": "number"
             }
            }
           }
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/api/order": {
   "post": {
    "operationId": "createOrder",
    "summary": "Create an order; returns pay_url for the customer",
    "description": "Confirm the order with the customer first. Files: file_urls per book, or multipart/form-data with the JSON in field `order` and files of book i in `book{i}_files[]` (50 MB per file, 120 MB / 20 files per order). The customer accepts the copyright declaration and pays on pay_url. Unpaid orders are deleted after 7 days.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/OrderRequest"
       }
      },
      "multipart/form-data": {
       "schema": {
        "type": "object",
        "properties": {
         "order": {
          "type": "string",
          "description": "OrderRequest as JSON"
         },
         "book0_files[]": {
          "type": "array",
          "items": {
           "type": "string",
           "format": "binary"
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/OrderCreated"
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/api/status": {
   "get": {
    "operationId": "orderStatus",
    "summary": "Payment and production state",
    "parameters": [
     {
      "name": "order",
      "in": "query",
      "required": true,
      "description": "order_id",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "token",
      "in": "query",
      "required": true,
      "description": "token from createOrder",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Status",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/api/files": {
   "post": {
    "operationId": "addFiles",
    "summary": "Add files to a book of an order not yet in production",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "order",
         "token",
         "file_urls"
        ],
        "properties": {
         "order": {
          "type": "integer"
         },
         "token": {
          "type": "string"
         },
         "book": {
          "type": "integer",
          "default": 0
         },
         "file_urls": {
          "type": "array",
          "items": {
           "type": "string"
          }
         }
        }
       }
      },
      "multipart/form-data": {
       "schema": {
        "type": "object",
        "properties": {
         "order": {
          "type": "integer"
         },
         "token": {
          "type": "string"
         },
         "book": {
          "type": "integer"
         },
         "files[]": {
          "type": "array",
          "items": {
           "type": "string",
           "format": "binary"
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Files added",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "schemas": {
   "Book": {
    "type": "object",
    "required": [
     "pages"
    ],
    "properties": {
     "pages": {
      "type": "integer",
      "description": "Number of pages (even). Range depends on binding/format/paper, see /api/options page_ranges."
     },
     "quantity": {
      "type": "integer",
      "minimum": 1,
      "default": 1
     },
     "color_pages": {
      "type": "integer",
      "minimum": 0,
      "default": 0,
      "description": "How many pages are in colour; 0 = black and white"
     },
     "format_id": {
      "type": "integer",
      "description": "Default: A5"
     },
     "binding_id": {
      "type": "integer"
     },
     "body_paper_id": {
      "type": "integer"
     },
     "body_finish": {
      "type": "string",
      "enum": [
       "mat",
       "gloss"
      ],
      "description": "Required only for the premium coated paper"
     },
     "cover_paper_id": {
      "type": "integer"
     },
     "cover_color_id": {
      "type": "integer"
     },
     "lamination_id": {
      "type": "integer"
     }
    }
   },
   "BookOrder": {
    "allOf": [
     {
      "$ref": "#/components/schemas/Book"
     },
     {
      "type": "object",
      "properties": {
       "file_urls": {
        "type": "array",
        "items": {
         "type": "string",
         "format": "uri"
        },
        "description": "Public https links to the print files (Google Drive / Dropbox / OneDrive shared as 'anyone with the link', or any direct link)"
       }
      }
     }
    ]
   },
   "OrderRequest": {
    "type": "object",
    "required": [
     "name",
     "email",
     "phone",
     "locker_id",
     "books"
    ],
    "properties": {
     "name": {
      "type": "string"
     },
     "email": {
      "type": "string",
      "format": "email"
     },
     "phone": {
      "type": "string",
      "description": "Bulgarian mobile, for BoxNow"
     },
     "locker_id": {
      "type": "string",
      "description": "id from /api/lockers"
     },
     "books": {
      "type": "array",
      "minItems": 1,
      "maxItems": 10,
      "items": {
       "$ref": "#/components/schemas/BookOrder"
      }
     },
     "invoice": {
      "type": "object",
      "properties": {
       "company": {
        "type": "string"
       },
       "eik": {
        "type": "string"
       },
       "vat": {
        "type": "string"
       },
       "mol": {
        "type": "string"
       },
       "address": {
        "type": "string"
       }
      }
     }
    }
   },
   "Quote": {
    "type": "object",
    "properties": {
     "currency": {
      "type": "string"
     },
     "books": {
      "type": "array",
      "items": {
       "type": "object"
      }
     },
     "books_total": {
      "type": "number"
     },
     "shipping": {
      "type": "object",
      "properties": {
       "fee": {
        "type": "number"
       },
       "free_from_books_total": {
        "type": "number"
       }
      }
     },
     "total": {
      "type": "number"
     },
     "order_url": {
      "type": "string",
      "description": "The site calculator prefilled with this book"
     }
    }
   },
   "OrderCreated": {
    "type": "object",
    "properties": {
     "order_id": {
      "type": "integer"
     },
     "order_ids": {
      "type": "array",
      "items": {
       "type": "integer"
      }
     },
     "token": {
      "type": "string"
     },
     "amount": {
      "type": "number"
     },
     "pay_url": {
      "type": "string"
     },
     "status_url": {
      "type": "string"
     },
     "files": {
      "type": "array"
     },
     "next_step": {
      "type": "string"
     }
    }
   },
   "Error": {
    "type": "object",
    "properties": {
     "success": {
      "type": "boolean"
     },
     "error": {
      "type": "string"
     }
    }
   }
  }
 }
}
