Accounting

Automate QuickBooks Invoice Entry — Parse PDFs Directly into QuickBooks Online

Every supplier invoice that arrives as a PDF can go directly into QuickBooks Online as a Bill — without anyone touching a keyboard.

By Othmane M., founder of DocuParse API · Last reviewed: 2026-10-20

The guide

  1. 1

    Get your credentials

    You need three things: a DocuParse API key (from your dashboard), a QuickBooks Online OAuth 2.0 access token, and your QBO Company ID. Create a QBO app at developer.intuit.com to get OAuth credentials.

  2. 2

    Extract the invoice

    Submit the PDF and fetch the result with parse_document (see the Python guide). The fetched data gives you every field QuickBooks needs:

    merchant  →  VendorRef.name
    date      →  TxnDate
    due_date  →  DueDate
    invoice_id → DocNumber
    line_items → Line[] array (Amount = line_total)
    total     →  QuickBooks calculates TotalAmt from the lines
  3. 3

    Find or create the vendor in QBO

    Query QBO for a Vendor matching the extracted merchant name. If none exists, create one automatically:

    def find_or_create_vendor(name, qbo_base, headers):
        safe = name.replace("'", "\\'")
        r = requests.get(f"{qbo_base}/query", headers=headers,
            params={"query": f"SELECT * FROM Vendor WHERE DisplayName LIKE '%{safe}%'",
                    "minorversion": "65"})
        vendors = r.json().get("QueryResponse", {}).get("Vendor", [])
        if vendors:
            return vendors[0]["Id"]
        r = requests.post(f"{qbo_base}/vendor", headers=headers,
            params={"minorversion": "65"},
            json={"DisplayName": name, "PrintOnCheckName": name})
        return r.json()["Vendor"]["Id"]
    Need your API key first?
    20 free documents/month — no credit card
    Sign up — get a free API key
  4. 4

    Check for duplicate invoices

    Before creating, query QBO for an existing Bill with the same DocNumber and VendorRef. If found, skip:

    def is_duplicate(invoice_number, qbo_base, headers):
        r = requests.get(f"{qbo_base}/query", headers=headers,
            params={"query": f"SELECT * FROM Bill WHERE DocNumber = '{invoice_number}'",
                    "minorversion": "65"})
        return len(r.json().get("QueryResponse", {}).get("Bill", [])) > 0
  5. 5

    Create the Bill in QuickBooks

    POST to the QBO /bill endpoint with the extracted fields mapped. QuickBooks calculates TotalAmt from the lines:

    bill = {
        "VendorRef": {"value": vendor_id},
        "TxnDate": invoice["date"],
        "DueDate": invoice["due_date"],
        "DocNumber": invoice["invoice_id"],
        "Line": [{
            "Amount": float(item["line_total"] or (float(item["price"] or 0) * (item["quantity"] or 1))),
            "DetailType": "AccountBasedExpenseLineDetail",
            "Description": item["description"],
            "AccountBasedExpenseLineDetail": {
                "AccountRef": {"value": "7"}
            }
        } for item in invoice["line_items"]]
    }
  6. 6

    Attach the original PDF to the bill

    QuickBooks stores the PDF as an Attachable linked to the bill, so the original is one click away when someone reviews it.

    import json
    
    def attach_pdf_to_bill(bill_id, pdf_path):
        meta = {
            "AttachableRef": [{"EntityRef": {"type": "Bill", "value": bill_id}}],
            "FileName": os.path.basename(pdf_path),
            "ContentType": "application/pdf",
        }
        with open(pdf_path, "rb") as f:
            r = requests.post(
                f"{QBO_BASE}/upload",
                headers={"Authorization": QBO_HEADERS["Authorization"], "Accept": "application/json"},
                files={
                    "file_metadata_0": (None, json.dumps(meta), "application/json"),
                    "file_content_0": (os.path.basename(pdf_path), f, "application/pdf"),
                },
            )
        r.raise_for_status()
        return r.json()

Full working example

python
import os, time, json, requests

QBO_BASE = f"https://quickbooks.api.intuit.com/v3/company/{os.environ['QBO_COMPANY_ID']}"
QBO_HEADERS = {"Authorization": f"Bearer {os.environ['QBO_ACCESS_TOKEN']}",
               "Content-Type": "application/json", "Accept": "application/json"}

API = "https://docuparseapi.com/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['DOCUPARSE_API_KEY']}"}

def parse_document(path: str) -> dict:
    # 1. Submit
    with open(path, "rb") as f:
        submit = requests.post(f"{API}/extract", headers=HEADERS,
                               files={"file": (os.path.basename(path), f)}, timeout=30).json()
    if not submit.get("success"):
        raise RuntimeError(f"[{submit['error']['code']}] {submit['error']['message']}")

    # 2. Fetch the result
    for _ in range(40):
        doc = requests.get(f"{API}/documents/{submit['document_id']}",
                           headers=HEADERS, timeout=30).json()
        if doc["status"] == "completed":
            return doc["data"]
        if doc["status"] == "failed":
            raise RuntimeError(f"Extraction failed: {submit['document_id']}")
        time.sleep(1.5)
    raise TimeoutError(submit["document_id"])

def find_or_create_vendor(name):
    safe = name.replace("'", "\\'")
    r = requests.get(f"{QBO_BASE}/query", headers=QBO_HEADERS,
        params={"query": f"SELECT * FROM Vendor WHERE DisplayName LIKE '%{safe}%'",
                "minorversion": "65"})
    vendors = r.json().get("QueryResponse", {}).get("Vendor", [])
    if vendors: return vendors[0]["Id"]
    r = requests.post(f"{QBO_BASE}/vendor", headers=QBO_HEADERS, params={"minorversion":"65"},
        json={"DisplayName": name})
    return r.json()["Vendor"]["Id"]

def attach_pdf_to_bill(bill_id, pdf_path):
    meta = {
        "AttachableRef": [{"EntityRef": {"type": "Bill", "value": bill_id}}],
        "FileName": os.path.basename(pdf_path),
        "ContentType": "application/pdf",
    }
    with open(pdf_path, "rb") as f:
        r = requests.post(
            f"{QBO_BASE}/upload",
            headers={"Authorization": QBO_HEADERS["Authorization"], "Accept": "application/json"},
            files={
                "file_metadata_0": (None, json.dumps(meta), "application/json"),
                "file_content_0": (os.path.basename(pdf_path), f, "application/pdf"),
            },
        )
    r.raise_for_status()
    return r.json()

def process(file_path):
    inv = parse_document(file_path)
    vendor_id = find_or_create_vendor(inv.get("merchant") or "Unknown")
    r = requests.post(f"{QBO_BASE}/bill", headers=QBO_HEADERS, params={"minorversion":"65"},
        json={"VendorRef":{"value":vendor_id}, "TxnDate":inv.get("date"),
              "DocNumber":inv.get("invoice_id"),
              "Line":[{"Amount":float(item["line_total"] or (float(item["price"] or 0) * (item["quantity"] or 1))),
                "DetailType":"AccountBasedExpenseLineDetail",
                "Description":item.get("description") or "", "AccountBasedExpenseLineDetail":{"AccountRef":{"value":"7"}}}
                for item in inv.get("line_items",[])]})
    bill_id = r.json()["Bill"]["Id"]
    attach_pdf_to_bill(bill_id, file_path)
    print(f"Bill created: {bill_id}")

process("invoice.pdf")

What gets extracted

FieldDescriptionDestination field
merchantThe vendor or store nameVendorRef.name
totalThe final charged amount including taxCalculated from lines
subtotalThe pre-tax amountLine[].Amount
taxThe tax amount chargedTaxCodeRef
dateInvoice or transaction date (ISO 8601)TxnDate
due_datePayment due date, or null if not presentDueDate
invoice_idInvoice number or receipt ID from the documentDocNumber
currencyISO 4217 currency code (USD, EUR, GBP, etc.)CurrencyRef
payment_methodCard type, cash, or other payment methodNot mapped
line_itemsArray of items with description, quantity, price, line_total, vat_rateLine[] array (Amount = line_total)

Common errors and fixes

MISSING_API_KEYAuthorization header missingAdd header: Authorization: Bearer YOUR_KEY
INVALID_API_KEYKey not recognisedCheck key in dashboard — regenerate if needed
LIMIT_EXCEEDEDMonthly document limit reachedUpgrade at docuparseapi.com/pricing
UNSUPPORTED_FILE_TYPEFile format not supportedUse PDF, JPG, PNG or CSV
FILE_TOO_LARGE_AUTHENTICATEDThe file is too largeCompress the image or split the PDF
TOO_MANY_PAGESMore than 20 pagesSplit the PDF into parts of up to 20 pages
EXTRACTION_FAILEDDocument could not be parsedTry a cleaner scan or different file

Ready to start?

20 documents a month free, with full API access. No credit card. Webhooks on Starter and Pro.

Sign up — get a free API key