API Documentation

How to use the Invoice Processing API.

Invoice Processing Endpoint
This endpoint processes an invoice from a public URL (image or PDF) and extracts structured data using Google Cloud Document AI.

Endpoint

POST /api/process-invoice

Request Body

The request body must be a JSON object with the following property:

  • url (string, required): The publicly accessible URL of the invoice file to be processed. Supported file types are images (JPEG, PNG) and PDF.

Example Request

Here is an example of how to call the API using cURL:

curl -X POST \
  [YOUR_APP_URL]/api/process-invoice \
  -H "Content-Type: application/json" \
  -d '{"url": "https://storage.googleapis.com/cloud-samples-data/documentai/invoice.pdf"}'

Note: Replace [YOUR_APP_URL] with the deployed URL of this application.

Success Response (200 OK)

A successful request will return a large JSON object directly from Google's Document AI service. This object contains all the extracted entities, text, and their confidence scores.

The structure is very detailed. Key information can typically be found within the document.entities array, which contains items like invoice_id, total_amount, line_item, etc., each with a mentionText and a confidence score.

Error Responses

  • 400 Bad Request: Returned if the url is missing from the request body or if the file at the URL is not a supported type (image/PDF).
  • 500 Internal Server Error: Returned if an unexpected error occurs during processing on the server, such as a failure to communicate with the Document AI service.