> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getcube.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Extraction Endpoint

<RequestExample>
  ```python python
  import requests
  import json
  import os 
  import mimetypes
  import base64

  def read_file(file_path: str) -> dict[str,str]:
      if not os.path.isfile(file_path):
          raise FileNotFoundError(f"No file found at {file_path}")
      
      file_name = os.path.basename(file_path)
      mime_type, _ = mimetypes.guess_type(file_path)
      
      with open(file_path, 'rb') as file:
          file_data = file.read()

      file_base64 = base64.b64encode(file_data).decode('utf-8')  
      
      return  {
          "id": "freight_document",
          "name": file_name,
          "content": file_base64,
          "mime_type": mime_type or 'application/octet-stream',
      }

  BASE_API_URL = "https://dashboard.getcube.ai/backend-api/api/custom/" 
  API_KEY = "YOUR API KEY"  


  headers = {
      "Api-Key": API_KEY,
      "Content-Type": "application/json",
  }

  document = read_file("data/example.PDF")

  document_processing_request_json = {
      "document": document
  }


  response = requests.post(
      f"{BASE_API_URL}/extractions",
      headers=headers,
      json={**document_processing_request_json},
  )

  print(response.json())
  ```

  ```bash curl
  curl -X 'POST' \
    'https://dashboard.getcube.ai/backend-api/api/custom/extractions' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -H 'Api-Key: YOUR_API_KEY' \
    -d '{
    "document": {
      "id": "string",
      "name": "string",
      "mime_type": "string",
      "content": "string"
    }
  }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200
  {
      "extraction": {
          "booking_id": "SHIP-001",
          "payment": {
              "total_price": 1500,
              "currency": "EUR"
          },
          "client": {
              "company_name": "ACME Corporation",
              "VAT_number": "GB123456789",
              "address": {
                  "city": "London",
                  "postal_code": "WC2N 5DU",
                  "country": "GB"
              },
              "email": "client@acme.com"
          },
          "shipments": [
              {
                  "shipment_id": "SHIP-001",
                  "sender": {
                      "company_name": "ACME Corporation",
                      "address": {
                          "country": "GB",
                          "postal_code": "WC2N 5DU",
                          "city": "London",
                          "line1": "123 Elm Street",
                          "line2": "Suite 500",
                          "state": null
                      },
                      "phone_number": "+44 20 7946 0958",
                      "email_address": "client@acme.com",
                      "pickup_datetime": {
                          "date": "2023-02-05",
                          "start_time": "08:00:00",
                          "end_time": "12:00:00"
                      },
                      "observations": null
                  },
                  "recipient": {
                      "company_name": "Beta Industries",
                      "address": {
                          "country": "DE",
                          "postal_code": "80331",
                          "city": "Munich",
                          "line1": "789 Pine Street",
                          "line2": null,
                          "state": "Bavaria"
                      },
                      "phone_number": "+49 89 123456",
                      "email_address": null,
                      "delivery_datetime": {
                          "date": "2023-03-05",
                          "start_time": "10:00:00",
                          "end_time": "16:00:00"
                      },
                      "observations": null
                  },
                  "goods": {
                      "packing": {
                          "units": 5,
                          "packing_type": "pallet",
                          "supplementary_parcels": null,
                          "pallets_on_ground": 5,
                          "number_eur_pallet": 0,
                          "observation": "UN1202 Class 3 Liquid, temperature control 5\\u00b0C to 25\\u00b0C."
                      },
                      "dimensions": {
                          "loading_meters": 0.4,
                          "volume": 1.44
                      },
                      "weight": 500,
                      "temperature_infos": {
                          "min_temperature": 5,
                          "max_temperature": 25,
                          "category": "Fresh"
                      },
                      "dangerous_goods_infos": [
                          {
                              "weight": null,
                              "UN_code": 1202,
                              "UN_label": "Liquid",
                              "UN_class": "3",
                              "UN_packing_group": null,
                              "ADR_tunnel_code": null
                          }
                      ]
                  },
                  "transport_constraints": {
                      "vehicle_type": null,
                      "body_type": null,
                      "tail_lift": null,
                      "crane": null
                  }
              }
          ]
      },
      "created": 1737133490,
      "likelihoods": {
          "booking_id": 0.6726946950754706,
          "payment": {
              "total_price": 0.999999091165773,
              "currency": 0.9999944422379444
          },
          "client": {
              "company_name": 1.0,
              "VAT_number": 0.6486153882881889,
              "address": {
                  "city": 0.9999988527586581,
                  "postal_code": 0.9999968263007362,
                  "country": 0.9994680776208963
              },
              "email": 0.9999933694113825
          },
          "shipments": [
              {
                  "shipment_id": 0.6726946950754706,
                  "sender": {
                      "company_name": 1.0,
                      "address": {
                          "country": 0.9994680776208963,
                          "postal_code": 0.9999968263007362,
                          "city": 0.9999988527586581,
                          "line1": 1.0,
                          "line2": 0.999996945503965,
                          "state": 0.9999784691637917
                      },
                      "phone_number": 0.9999545100307,
                      "email_address": 0.9999933694113825,
                      "pickup_datetime": {
                          "date": 0.995386165984811,
                          "start_time": 0.9959296666541886,
                          "end_time": 0.9999995679800934
                      },
                      "observations": 0.9999784691637917
                  },
                  "recipient": {
                      "company_name": 0.999994561441089,
                      "address": {
                          "country": 0.9999889589149532,
                          "postal_code": 0.9999995679800934,
                          "city": 0.9999974223173222,
                          "line1": 0.9999981375378344,
                          "line2": 0.9999784691637917,
                          "state": 0.9999976607241361
                      },
                      "phone_number": 0.9999934886141991,
                      "email_address": 0.9999784691637917,
                      "delivery_datetime": {
                          "date": 0.9995688277314909,
                          "start_time": 0.9999645227323332,
                          "end_time": 0.9999998063873687
                      },
                      "observations": 0.9999784691637917
                  },
                  "goods": {
                      "packing": {
                          "units": 0.9999988527586581,
                          "packing_type": 0.999720111226173,
                          "supplementary_parcels": 0.9999784691637917,
                          "pallets_on_ground": 0.9999988527586581,
                          "number_eur_pallet": 0.8337704119108418,
                          "observation": 0.3338635841915964
                      },
                      "dimensions": {
                          "loading_meters": 0.9879654652950378,
                          "volume": 0.9999984951481323
                      },
                      "weight": 0.9999984951481323,
                      "temperature_infos": {
                          "min_temperature": 0.9999988527586581,
                          "max_temperature": 0.9999978991308068,
                          "category": 0.9999826412106655
                      },
                      "dangerous_goods_infos": [
                          {
                              "weight": 0.9999784691637917,
                              "UN_code": 0.9986591072011969,
                              "UN_label": 0.6405346504790916,
                              "UN_class": 0.9999996871837189,
                              "UN_packing_group": 0.9999784691637917,
                              "ADR_tunnel_code": 0.9999784691637917
                          }
                      ]
                  },
                  "transport_constraints": {
                      "vehicle_type": 0.9999784691637917,
                      "body_type": 0.9999784691637917,
                      "tail_lift": 0.9999784691637917,
                      "crane": 0.9999784691637917
                  }
              }
          ]
      },
      "regex_instruction_results": [
          {
              "instruction": {
                  "name": "VAT Number",
                  "pattern": "[Ff][Rr]\\\\s*(\\\\d\\\\s*){11}",
                  "description": "All potential VAT numbers in the documents"
              },
              "hits": [
                  "FR12 345 678 901"
              ]
          }
      ],
      "text_operations_message": "### I Found 1 matches for the regex pattern \'VAT Number\' (All potential VAT numbers in the documents):\\n- FR12 345 678 901\\n",
      "schema_validation_error": null
  }
  ```
</ResponseExample>
