Skip to content

Processing Documents

FSCO provides APIs for creating and uploading documents. The typical workflow for processing documents is:

  1. Create a document record using the API
  2. Upload the document file
  3. Receive webhook notifications as the document is processed
  1. Create Document

    When you create a document, FSCO will:

    • Generate a unique document ID
    • Associate it with your specified template and collection
    • Return the document ID immediately
    • Return a webhook notification when the document is created
  2. Upload Document File

    After uploading a file, FSCO will:

    • Validate and scan the file
    • Process it using the template’s AI model and prompts
    • Extract the requested data
    • Send webhook notifications at each stage

The following webhook events are sent during document processing:

  • document.created - Sent when the document record is created
  • document.updated - Sent when the document record was updated
  • ocr.started - Sent when document text extraction started
  • ocr.completed - Sent when document text extraction is completed
  • ocr.failed - Sent when the document text could not be extracted
  • ai.started - Sent when AI processing begins
  • ai.typeSelected - Sent when the document type is determined by the AI processor
  • ai.processed - Sent when AI processing is completed
  • ai.failed - Sent when the AI processing failed

Each webhook includes the document ID and current status, allowing you to track the document’s progress through your system.

On receipt of a webhook failure event, you can retrieve the document activity using the Get Document Activity endpoint.

This guide covers both creating new documents and uploading existing document files.

Before you begin, ensure you have:

  • A valid FSCO API key
  • Your application’s environment configured with the API key
  • A template ID for document processing
  • A collection ID for organizing documents
POST /v2/document
{
"refId": "2a2e4823-017c-4acd-a683-87e91c647500",
"docExt": "application/pdf",
"docName": "figma_invoice_2025-05-06.pdf",
"docType": "invoice",
"isTest": false,
"templateId": "38aff0fb-3df4-41f3-a266-3b85984f72b8",
"source": "My API",
"uploadBatchId": "2993F653-E268-4CE6-A6A0-A5FC05DB1888"
}

The request requires:

  • templateId: The ID of the template to use for processing
  • refId: The ID of the document in your system
  • docExt: The extension of the document file
  • docName: The name of the document file
  • docType: The type of document (from the list of supported document types)
  • isTest: Whether the document is a test
  • source: The source of the document (e.g. “My API”)
  • uploadBatchId: The ID of the upload
create-document.sh
#!/bin/bash
curl -X POST "https://api.fsco.io/v2/document" \
-H "x-api-key: $FSCO_API_KEY" \
-H "x-api-secret: $FSCO_API_SECRET" \
-H "Content-Type: application/json" \
-d '{
"refId": "2a2e4823-017c-4acd-a683-87e91c647500",
"docExt": "application/pdf",
"docName": "figma_invoice_2025-05-06.pdf",
"docType": "invoice",
"isTest": false,
"templateId": "8c1d496f-2827-4750-a11f-74b48c11108d",
"collectionId": "9d2e507g-3938-5861-b22g-85c59d22219e",
"source": "My API",
"uploadBatchId": "2993F653-E268-4CE6-A6A0-A5FC05DB1888"
}'
response.json
{
"id": "bca4e809-3d44-4c27-9cda-89dc4471739b",
"createdAt": "2025-05-20T00:12:45.011Z",
"updatedAt": "2025-05-20T00:12:45.011Z",
"isTest": false,
"config": null,
"fileData": null,
"ocrProvider": "GOOGLE_DOCUMENT_AI",
"ocrData": null,
"docExt": "application/pdf",
"docName": "my_invoice_2025-05-06.pdf",
"docType": "invoice",
"uploadBatchId": "4993F653-E268-4CE6-A6A0-A5FC05DB1888",
"refId": "3a2e4823-017c-4acd-a683-87e91c647500",
"blobId": "29a88889-e559-4d8b-8ab8-820090aace9b",
"isPublic": false,
"isUploaded": false,
"source": "My API",
"webhookId": null,
"organisationId": "00b4b8e6-6e9c-4ec8-8bc0-4f27cba57e26",
"userId": "0d05e804-cb6c-4bd4-8bf7-2d283b466eca",
"status": "created",
"version": 1,
"prompts": [
{
"id": "91e0fd01-4df3-422b-afa7-adfd489cc0f5",
"name": "Issuer",
"format": "",
"children": [],
"itemType": "singleLine",
"fieldType": "string",
"description": "Who is the issuer of this invoice"
}
],
"providerModelId": "7b313983-7d8c-43ca-9714-c6767201bd3f",
"documentGroups": [],
"providerModel": {
"providerModelId": "7b313983-7d8c-43ca-9714-c6767201bd3f",
"providerName": "OPENAI",
"modelName": "GPT_4O",
"description": "Default provider model",
"displayName": "GPT_4O"
},
"uploadUrl": "my-upload-url",
"downloadUrl": "my-download-url"
}
PUT /v2/document/{documentId}

The request requires a multipart form with:

  • file: The document file to upload (PDF, DOCX, etc.)
upload-document-file.sh
#!/bin/bash
curl -X PUT "https://api.fsco.io/v2/document/8c1d496f-2827-4750-a11f-74b48c11108d/file" \
-H "x-api-key: $FSCO_API_KEY" \
-H "x-api-secret: $FSCO_API_SECRET" \
-H "Content-Type: multipart/form-data" \
-F "file=@/path/to/your/document.pdf"
response.json
{
"blobId": "29a88889-e559-4d8b-8ab8-820090aace91",
"key": "the_generated_key_path",
"public": false,
"access": {
"get": "the_generated_get_url",
"put": "the_generated_put_url",
"delete": "the_generated_delete_url"
}
}
  • Document files must be in a supported format (PDF, DOCX, etc.)
  • The template ID must be valid and active
  • The collection ID must exist in your organization
  • Document processing is asynchronous and may take some time
  • You can track document processing status through the document activity endpoint