First Integration
Overview
Section titled “Overview”In this tutorial, you’ll learn how to connect to the DocuStack API, upload a document, and retrieve extracted data — all from code. By the end, you’ll have a working integration that processes documents programmatically.
Prerequisites
Section titled “Prerequisites”- A DocuStack account with API access
- An API key from your workspace settings
- A sample PDF document to process
Step 1: Authenticate with the API
Section titled “Step 1: Authenticate with the API”All API requests require a Bearer token. Use your API key in the Authorization header:
curl -X GET https://api.docustack.com/v1/workspaces \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json"import requests
API_KEY = "YOUR_API_KEY"BASE_URL = "https://api.docustack.com/v1"
headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json",}
response = requests.get(f"{BASE_URL}/workspaces", headers=headers)print(response.json())const API_KEY = "YOUR_API_KEY";const BASE_URL = "https://api.docustack.com/v1";
const response = await fetch(`${BASE_URL}/workspaces`, { headers: { Authorization: `Bearer ${API_KEY}`, "Content-Type": "application/json", },});
const data = await response.json();console.log(data);Step 2: Upload a document
Section titled “Step 2: Upload a document”Upload a document to your workspace for processing:
curl -X POST https://api.docustack.com/v1/documents \ -H "Authorization: Bearer YOUR_API_KEY" \ -F "file=@invoice.pdf" \ -F "workspace_id=ws_abc123"with open("invoice.pdf", "rb") as f: response = requests.post( f"{BASE_URL}/documents", headers={"Authorization": f"Bearer {API_KEY}"}, files={"file": f}, data={"workspace_id": "ws_abc123"}, )
document = response.json()document_id = document["id"]print(f"Document uploaded: {document_id}")const formData = new FormData();formData.append("file", fs.createReadStream("invoice.pdf"));formData.append("workspace_id", "ws_abc123");
const response = await fetch(`${BASE_URL}/documents`, { method: "POST", headers: { Authorization: `Bearer ${API_KEY}` }, body: formData,});
const document = await response.json();console.log(`Document uploaded: ${document.id}`);Step 3: Retrieve extraction results
Section titled “Step 3: Retrieve extraction results”Once processing completes, retrieve the extracted data:
curl -X GET https://api.docustack.com/v1/documents/doc_xyz789/results \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json"response = requests.get( f"{BASE_URL}/documents/{document_id}/results", headers=headers,)
results = response.json()for field in results["fields"]: print(f"{field['name']}: {field['value']} (confidence: {field['confidence']})")const response = await fetch( `${BASE_URL}/documents/${document.id}/results`, { headers: { Authorization: `Bearer ${API_KEY}`, "Content-Type": "application/json", }, });
const results = await response.json();results.fields.forEach((field) => { console.log(`${field.name}: ${field.value} (confidence: ${field.confidence})`);});What’s next
Section titled “What’s next”Now that you’ve completed your first API integration:
- Schema Builder Guide — Learn how to define custom extraction schemas.
- Product Guides — Explore document management and other platform features.