The guide
- 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
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
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"]Sign up — get a free API keyNeed your API key first?20 free documents/month — no credit card - 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
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
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
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
| Field | Description | Destination field |
|---|---|---|
merchant | The vendor or store name | VendorRef.name |
total | The final charged amount including tax | Calculated from lines |
subtotal | The pre-tax amount | Line[].Amount |
tax | The tax amount charged | TaxCodeRef |
date | Invoice or transaction date (ISO 8601) | TxnDate |
due_date | Payment due date, or null if not present | DueDate |
invoice_id | Invoice number or receipt ID from the document | DocNumber |
currency | ISO 4217 currency code (USD, EUR, GBP, etc.) | CurrencyRef |
payment_method | Card type, cash, or other payment method | Not mapped |
line_items | Array of items with description, quantity, price, line_total, vat_rate | Line[] array (Amount = line_total) |
Common errors and fixes
MISSING_API_KEY | Authorization header missing | Add header: Authorization: Bearer YOUR_KEY |
INVALID_API_KEY | Key not recognised | Check key in dashboard — regenerate if needed |
LIMIT_EXCEEDED | Monthly document limit reached | Upgrade at docuparseapi.com/pricing |
UNSUPPORTED_FILE_TYPE | File format not supported | Use PDF, JPG, PNG or CSV |
FILE_TOO_LARGE_AUTHENTICATED | The file is too large | Compress the image or split the PDF |
TOO_MANY_PAGES | More than 20 pages | Split the PDF into parts of up to 20 pages |
EXTRACTION_FAILED | Document could not be parsed | Try 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.