  {
    "openapi": "3.0.1",
    "info": {
      "title": "Parser Expert API",
      "description": "API documentation for Parser Expert.",
      "license": {
        "name": "MIT"
      },
      "version": "1.0.0"
    },
    "servers": [
      {
        "url": "https://api.parser.expert"
      }
    ],
    "security": [
      {
        "apiKeyAuth": []
      }
    ],
    "paths": {
      "/v1/upload": {
        "post": {
          "summary": "Upload Data",
          "description": "Upload data to the Parser Expert API. You can upload either a file or provide a webpage URL.",
          "requestBody": {
            "required": true,
            "content": {
              "multipart/form-data": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "file": {
                      "type": "string",
                      "format": "binary",
                      "description": "The file to upload. Supported formats are PDF, DOCX, Image, Txt File (maximum of 10 pages per document)."
                    },
                    "bucket_id": {
                      "type": "string",
                      "description": "The ID of the bucket where the data will be stored.Refer to Quickstart for set extraction fields"
                    },
                    "webpage_url": {
                      "type": "string",
                      "description": "The URL of the webpage to extract content from. This will be ignored if `file` is provided."
                    }
                  },
                  "required": ["bucket_id"]
                }
              }
            }
          },
          "responses": {
            "200": {
              "description": "Extract upserted successfully",
              "content": {
                "application/json": {
                  "schema": {
                    "type": "object",
                    "properties": {
                      "data": {
                        "type": "object",
                        "properties": {
                          "parser_id": {
                            "type": "string",
                            "description": "The ID of the parser."
                          }
                        }
                      },
                      "message": {
                        "type": "string",
                        "description": "Success message."
                      }
                    }
                  },
                  "example": {
                    "data": {
                      "parser_id": "f555c13a-846f-4505-95fe-8f72b39edef9"
                    },
                    "message": "Extract upserted successfully"
                  }
                }
              }
            },
            "400": {"$ref": "#/components/responses/BadRequest"},
            "401": {"$ref": "#/components/responses/Unauthorized"},
            "403": {"$ref": "#/components/responses/Forbidden"},
            "404": {"$ref": "#/components/responses/NotFound"},
            "405": {"$ref": "#/components/responses/MethodNotAllowed"},
            "424": {"$ref": "#/components/responses/FailedDependency"},
            "500": {"$ref": "#/components/responses/InternalServerError"}
          },
          "x-codeSamples": [
            {
              "lang": "Python",
              "source": "import requests\n\nurl = \"https://api.parser.expert/v1/upload\"\n\nheaders = {\n    'X-API-Key': 'sk-xxxx'\n}\n\nfiles = {\n    'file': open('/path/to/your/file.pdf', 'rb'),\n    'bucket_id': (None, '100202')\n}\n\nresponse = requests.post(url, headers=headers, files=files)\n\nprint(response.text)"
            },
            {
              "lang": "Go",
              "source": "package main\n\nimport (\n    \"bytes\"\n    \"fmt\"\n    \"mime/multipart\"\n    \"net/http\"\n    \"os\"\n)\n\nfunc main() {\n    url := \"https://api.parser.expert/v1/upload\"\n    apiKey := \"sk-xxxxxxxx\"\n    filePath := \"/path/to/your/file.pdf\"\n\n    file, err := os.Open(filePath)\n    if err != nil {\n        panic(err)\n    }\n    defer file.Close()\n\n    body := &bytes.Buffer{}\n    writer := multipart.NewWriter(body)\n    part, err := writer.CreateFormFile(\"file\", \"file.pdf\")\n    if err != nil {\n        panic(err)\n    }\n    _, err = io.Copy(part, file)\n    if err != nil {\n        panic(err)\n    }\n\n    _ = writer.WriteField(\"bucket_id\", \"100202\")\n    writer.Close()\n\n    req, err := http.NewRequest(\"POST\", url, body)\n    if err != nil {\n        panic(err)\n    }\n    req.Header.Add(\"X-API-Key\", apiKey)\n    req.Header.Set(\"Content-Type\", writer.FormDataContentType())\n\n    client := &http.Client{}\n    resp, err := client.Do(req)\n    if err != nil {\n        panic(err)\n    }\n    defer resp.Body.Close()\n\n    fmt.Println(\"Response Status:\", resp.Status)\n}"
            },
            {
              "lang": "Curl",
              "source": "curl --location --request POST 'https://api.parser.expert/v1/upload' \\\n--header 'X-API-Key: sk-xxxxxxxx' \\\n--form 'file=@\"/path/to/your/file.pdf\"' \\\n--form 'bucket_id=\"100202\"'"
            },
            {
              "lang": "Java",
              "source": "import java.io.File;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.OutputStream;\nimport java.net.HttpURLConnection;\nimport java.net.URL;\n\npublic class UploadFile {\n    public static void main(String[] args) throws IOException {\n        String url = \"https://api.parser.expert/v1/upload\";\n        String apiKey = \"sk-xxxxxxxx\";\n        String boundary = \"Boundary-\" + System.currentTimeMillis();\n        String lineEnd = \"\\r\\n\";\n        String twoHyphens = \"--\";\n\n        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();\n        connection.setDoOutput(true);\n        connection.setRequestMethod(\"POST\");\n        connection.setRequestProperty(\"X-API-Key\", apiKey);\n        connection.setRequestProperty(\"Content-Type\", \"multipart/form-data; boundary=\" + boundary);\n\n        OutputStream outputStream = connection.getOutputStream();\n\n        // File part\n        outputStream.write((twoHyphens + boundary + lineEnd).getBytes());\n        outputStream.write(\"Content-Disposition: form-data; name=\\\"file\\\"; filename=\\\"file.pdf\\\"\".getBytes());\n        outputStream.write(lineEnd.getBytes());\n        outputStream.write(\"Content-Type: application/pdf\".getBytes());\n        outputStream.write(lineEnd.getBytes());\n        outputStream.write(lineEnd.getBytes());\n\n        FileInputStream fileInputStream = new FileInputStream(new File(\"/path/to/your/file.pdf\"));\n        int bytesRead;\n        byte[] buffer = new byte[4096];\n        while ((bytesRead = fileInputStream.read(buffer)) != -1) {\n            outputStream.write(buffer, 0, bytesRead);\n        }\n        outputStream.write(lineEnd.getBytes());\n\n        // bucket_id part\n        outputStream.write((twoHyphens + boundary + lineEnd).getBytes());\n        outputStream.write(\"Content-Disposition: form-data; name=\\\"bucket_id\\\"\".getBytes());\n        outputStream.write(lineEnd.getBytes());\n        outputStream.write(lineEnd.getBytes());\n        outputStream.write(\"100202\".getBytes());\n        outputStream.write(lineEnd.getBytes());\n\n        // End part\n        outputStream.write((twoHyphens + boundary + twoHyphens + lineEnd).getBytes());\n        outputStream.flush();\n        outputStream.close();\n\n        int responseCode = connection.getResponseCode();\n        System.out.println(\"Response Code: \" + responseCode);\n    }\n}"
            },

            {
              "lang": "JavaScript",
              "source": "const axios = require('axios');\nconst FormData = require('form-data');\nconst fs = require('fs');\n\nconst url = 'https://api.parser.expert/v1/upload';\nconst apiKey = 'sk-xxxxxxxx';\nconst filePath = '/path/to/your/file.pdf';\n\nconst form = new FormData();\nform.append('file', fs.createReadStream(filePath));\nform.append('bucket_id', '100202');\n\naxios.post(url, form, {\n    headers: {\n        'X-API-Key': apiKey,\n        ...form.getHeaders()\n    }\n}).then(response => {\n    console.log(response.data);\n}).catch(error => {\n    console.error(error);\n});"
            },
            {
              "lang": "PHP",
              "source": "<?php\n\n$apiKey = 'sk-xxxxxxxx';\n$filePath = '/path/to/your/file.pdf';\n\n$ch = curl_init();\n\ncurl_setopt($ch, CURLOPT_URL, 'https://api.parser.expert/v1/upload');\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);\n\n$post = array(\n    'file' => new CURLFile($filePath),\n    'bucket_id' => '100202'\n);\n$headers = array(\n    'X-API-Key: ' . $apiKey\n);\n\ncurl_setopt($ch, CURLOPT_POSTFIELDS, $post);\ncurl_setopt($ch, CURLOPT_HTTPHEADER, $headers);\n\n$response = curl_exec($ch);\nif (curl_errno($ch)) {\n    echo 'Error:' . curl_error($ch);\n}\n\ncurl_close($ch);\n\necho $response;\n?>"
            }
          ]
        }
      },
      "/v1/extracts": {
        "get": {
          "summary": "Get Extracted Data",
          "description": "Retrieve the extracted data using the parser ID and bucket ID.",
          "parameters": [
            {
              "name": "parser_id",
              "in": "query",
              "required": true,
              "schema": {
                "type": "string"
              },
              "description": "The ID of the parser. The parser ID is returned when content is uploaded."
            },
            {
              "name": "bucket_id",
              "in": "query",
              "required": true,
              "schema": {
                "type": "string"
              },
              "description": "The ID of the bucket."
            }
          ],
          "responses": {
            "200": {
              "description": "Processed successfully",
              "content": {
                "application/json": {
                  "schema": {
                    "type": "object",
                    "properties": {
                      "data": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "parsed_data": {
                              "type": "object",
                              "additionalProperties": true
                            },
                            "parser_id": {
                              "type": "string",
                              "description": "The ID of the parser."
                            },
                            "status": {
                              "type": "string",
                              "description": "The status of the extraction. Available values are  `pending` `parsed` `error`."
                            },
                            "updated_at": {
                              "type": "string",
                              "format": "date-time",
                              "description": "The last update time. The format is ISO 8601. For example, `2024-07-12T20:30:03.042Z`."
                            }
                          }
                        }
                      },
                      "message": {
                        "type": "string",
                        "description": "Success message."
                      }
                    }
                  },
                  "examples": {
                    "pending": {
                      "value": {
                        "data": [
                          {
                            "parsed_data": {},
                            "parser_id": "f555c13a-846f-4505-95fe-8f72b39edef9",
                            "status": "pending",
                            "updated_at": "2024-07-12T20:30:03.042Z"
                          }
                        ],
                        "message": "Processed successfully"
                      }
                    },
                    "completed": {
                      "value": {
                        "data": [
                          {
                            "parsed_data": {
                              "amount_due": 2300,
                              "billing_address": "789 Enterprise Blvd, Innovation City, MA 54321",
                              "currency_code": null,
                              "customer_name": "Innovations Acme",
                              "due_date": "2024-04-19",
                              "invoice_date": "2024-03-20",
                              "invoice_id": "FA20240001",
                              "invoice_total": null,
                              "items": [
                                {
                                  "amount": 300,
                                  "description": "Brand Identity Design 1 Hour",
                                  "product_code": "BRD",
                                  "quantity": 1,
                                  "service_date": "2024-03-15",
                                  "tax": null,
                                  "tax_rate": null,
                                  "unit": null,
                                  "unit_price": 300
                                }
                              ],
                              "purchase_order": "PO1234343",
                              "subtotal": 2500,
                              "tax": 200,
                              "total_discount": null,
                              "vendor_address": null,
                              "vendor_name": "Acme Inc."
                            },
                            "parser_id": "f555c13a-846f-4505-95fe-8f72b39edef9",
                            "status": "parsed",
                            "updated_at": "2024-07-12T20:30:20.286Z"
                          }
                        ],
                        "message": "Processed successfully"
                      }
                    }
                  }
                }
              }
            },
            "400": {"$ref": "#/components/responses/BadRequest"},
            "401": {"$ref": "#/components/responses/Unauthorized"},
            "403": {"$ref": "#/components/responses/Forbidden"},
            "404": {"$ref": "#/components/responses/NotFound"},
            "405": {"$ref": "#/components/responses/MethodNotAllowed"},
            "424": {"$ref": "#/components/responses/FailedDependency"},
            "500": {"$ref": "#/components/responses/InternalServerError"}
          }
        }
      }
    },
    "components": {
      "schemas": {
        "Error": {
          "type": "object",
          "properties": {
            "error": {
              "type": "string"
            },
            "message": {
              "type": "string"
            }
          }
        }
      },
      "securitySchemes": {
        "apiKeyAuth": {
          "type": "apiKey",
          "in": "header",
          "name": "X-API-Key"
        }
      },
      "responses": {
        "BadRequest": {
          "description": "Bad Request",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Error"
              }
            }
          }
        },
        "Unauthorized": {
          "description": "Unauthorized",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Error"
              }
            }
          }
        },
        "Forbidden": {
          "description": "Forbidden",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Error"
              }
            }
          }
        },
        "NotFound": {
          "description": "Not Found",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Error"
              }
            }
          }
        },
        "MethodNotAllowed": {
          "description": "Method Not Allowed",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Error"
              }
            }
          }
        },
        "FailedDependency": {
          "description": "Failed Dependency",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Error"
              }
            }
          }
        },
        "InternalServerError": {
          "description": "Internal Server Error",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Error"
              }
            }
          }
        }
      }
    }
  }
