7 min read

Make Your First API Call

Process your first document with DocuRift in under 5 minutes

Process your first shipping document with DocuRift in under 5 minutes. This guide shows you how to extract data from an invoice using curl, Python, or JavaScript.

Prerequisites

Before you start, make sure you have:

  • [x] DocuRift account with API key (Get API key)
  • [x] A sample document (PDF or image) or use our sample invoice
  • [x] curl, Python 3.7+, or Node.js 14+ installed

API Endpoint

DocuRift provides a simple REST API for document processing:

POST https://api.docurift.com/v1/process

Authentication: Bearer token in Authorization header

Request: Multipart form data with document file

Response: Structured JSON with extracted data

Quick Start: Process a Sample Invoice

Let's extract data from a sample commercial invoice.

Download Sample Document

First, download our sample invoice:

curl -O https://docurift.com/samples/sample-invoice.pdf

Or use your own invoice/shipping document.

Option 1: Using curl

The simplest way to test the API:

curl -X POST https://api.docurift.com/v1/process \
  -H "Authorization: Bearer frc_your_api_key_here" \
  -F "file=@sample-invoice.pdf" \
  -F "document_type=invoice"

Replace frc_your_api_key_here with your actual API key.

Option 2: Using Python

Install the DocuRift Python SDK:

pip install docurift

Then create process_invoice.py:

import os
from docurift import DocuRift

# Initialize client with API key from environment
client = DocuRift(api_key=os.getenv('DOCURIFT_API_KEY'))

# Process the invoice
with open('sample-invoice.pdf', 'rb') as file:
    result = client.process(
        file=file,
        document_type='invoice'
    )

# Print extracted data
print("Invoice Number:", result.invoice_number)
print("Invoice Date:", result.invoice_date)
print("Vendor:", result.vendor.name)
print("Total Amount:", result.total_amount)

# Access line items
for item in result.line_items:
    print(f"  - {item.description}: {item.quantity} x ${item.unit_price}")

Run it:

export DOCURIFT_API_KEY=frc_your_api_key_here
python process_invoice.py

Option 3: Using JavaScript/Node.js

Install the DocuRift JavaScript SDK:

npm install docurift

Then create process-invoice.js:

require('dotenv').config();
const { DocuRift } = require('docurift');
const fs = require('fs');

// Initialize client with API key from environment
const client = new DocuRift({
  apiKey: process.env.DOCURIFT_API_KEY
});

async function processInvoice() {
  try {
    // Read the file
    const file = fs.createReadStream('sample-invoice.pdf');

    // Process the invoice
    const result = await client.process({
      file: file,
      documentType: 'invoice'
    });

    // Print extracted data
    console.log('Invoice Number:', result.invoiceNumber);
    console.log('Invoice Date:', result.invoiceDate);
    console.log('Vendor:', result.vendor.name);
    console.log('Total Amount:', result.totalAmount);

    // Access line items
    result.lineItems.forEach(item => {
      console.log(`  - ${item.description}: ${item.quantity} x $${item.unitPrice}`);
    });

  } catch (error) {
    console.error('Error processing invoice:', error.message);
  }
}

processInvoice();

Run it:

DOCURIFT_API_KEY=frc_your_api_key_here node process-invoice.js

Option 4: Using TypeScript

import { DocuRift } from 'docurift';
import fs from 'fs';

// Initialize client
const client = new DocuRift({
  apiKey: process.env.DOCURIFT_API_KEY as string
});

async function processInvoice() {
  const file = fs.createReadStream('sample-invoice.pdf');

  const result = await client.process({
    file: file,
    documentType: 'invoice'
  });

  console.log('Extracted Data:', result);
}

processInvoice();

Understanding the Response

The API returns structured JSON with extracted data. Here's a sample response:

{
  "id": "doc_abc123xyz456",
  "status": "completed",
  "document_type": "invoice",
  "processed_at": "2024-01-26T10:30:00Z",
  "pages_processed": 1,
  "confidence": 0.97,
  "data": {
    "invoice_number": "INV-2024-001",
    "invoice_date": "2024-01-15",
    "due_date": "2024-02-15",
    "currency": "USD",
    "vendor": {
      "name": "Acme Shipping Co.",
      "address": "123 Harbor Blvd, Los Angeles, CA 90021",
      "tax_id": "12-3456789",
      "email": "billing@acmeshipping.com"
    },
    "customer": {
      "name": "Global Imports Inc.",
      "address": "456 Trade St, New York, NY 10001",
      "tax_id": "98-7654321"
    },
    "line_items": [
      {
        "description": "Ocean Freight - Container 20ft",
        "quantity": 2,
        "unit_price": 1500.00,
        "total": 3000.00
      },
      {
        "description": "Documentation Fee",
        "quantity": 1,
        "unit_price": 150.00,
        "total": 150.00
      }
    ],
    "subtotal": 3150.00,
    "tax_rate": 0.08,
    "tax_amount": 252.00,
    "total_amount": 3402.00,
    "payment_terms": "Net 30",
    "notes": "Payment due within 30 days of invoice date"
  }
}

Response Fields

  • id: Unique document ID for reference
  • status: Processing status (completed, processing, failed)
  • document_type: Type of document processed
  • processed_at: UTC timestamp of processing completion
  • pages_processed: Number of pages consumed from your credits
  • confidence: Overall extraction confidence (0-1 scale)
  • data: Extracted structured data (varies by document type)

Confidence Scores

DocuRift provides confidence scores for data quality:

  • 0.95 - 1.0: Excellent - High confidence in extracted data
  • 0.85 - 0.94: Good - Minor verification recommended
  • 0.70 - 0.84: Fair - Review important fields
  • Below 0.70: Low - Manual review recommended

Error Handling

Handle common errors gracefully:

Python Example

from docurift import DocuRift, DocuRiftError

client = DocuRift(api_key=os.getenv('DOCURIFT_API_KEY'))

try:
    result = client.process(file=file, document_type='invoice')
    print("Success:", result)
except DocuRiftError as e:
    if e.status_code == 401:
        print("Authentication failed. Check your API key.")
    elif e.status_code == 402:
        print("Insufficient credits. Add credits to continue.")
    elif e.status_code == 400:
        print("Invalid request:", e.message)
    elif e.status_code == 429:
        print("Rate limit exceeded. Retry in a moment.")
    else:
        print(f"Error: {e.message}")

JavaScript Example

try {
  const result = await client.process({
    file: file,
    documentType: 'invoice'
  });
  console.log('Success:', result);
} catch (error) {
  switch (error.statusCode) {
    case 401:
      console.error('Authentication failed. Check your API key.');
      break;
    case 402:
      console.error('Insufficient credits. Add credits to continue.');
      break;
    case 400:
      console.error('Invalid request:', error.message);
      break;
    case 429:
      console.error('Rate limit exceeded. Retry in a moment.');
      break;
    default:
      console.error('Error:', error.message);
  }
}

Common HTTP Status Codes

| Code | Meaning | Solution | |------|---------|----------| | 200 | Success | Document processed successfully | | 400 | Bad Request | Check file format and parameters | | 401 | Unauthorized | Verify your API key is correct | | 402 | Payment Required | Add credits to your account | | 413 | File Too Large | File exceeds 10MB limit | | 415 | Unsupported Media Type | Use PDF, JPG, or PNG format | | 429 | Rate Limit Exceeded | Reduce request rate or upgrade plan | | 500 | Server Error | Contact support if persistent |

Supported File Formats

DocuRift accepts these file formats:

  • PDF: Single or multi-page (max 10MB)
  • JPEG/JPG: Images of documents (max 10MB)
  • PNG: Images of documents (max 10MB)

File size limit: 10MB per file

Multi-page PDFs: Each page counts as 1 page credit

Check Your Credit Balance

After processing, check your remaining credits:

curl

curl https://api.docurift.com/v1/account/credits \
  -H "Authorization: Bearer frc_your_api_key_here"

Python

balance = client.get_credit_balance()
print(f"Remaining credits: {balance.pages_remaining} pages")

JavaScript

const balance = await client.getCreditBalance();
console.log(`Remaining credits: ${balance.pagesRemaining} pages`);

Response:

{
  "pages_remaining": 47,
  "pages_used": 3,
  "subscription_tier": "free"
}

Processing Different Document Types

DocuRift supports 10+ document types. Specify the type for optimized extraction:

# Bill of Lading
result = client.process(file=file, document_type='bill_of_lading')

# Packing List
result = client.process(file=file, document_type='packing_list')

# Commercial Invoice
result = client.process(file=file, document_type='invoice')

# Auto-detect (less accurate)
result = client.process(file=file)

See Supported Document Types for full list.

Next Steps

Congratulations! You've processed your first document with DocuRift.

Explore More Features

Need Help?

Rate Limits

Free tier: 10 requests/minute, 100 requests/hour

Paid tier: 100 requests/minute, 10,000 requests/hour

Need higher limits? Contact sales@docurift.com for enterprise plans.