# Integrate Paige with the Business Central API

For developers: the four Business Central API calls that turn a Paige invoice into a draft purchase invoice with the PDF attached — create the invoice, add lines, create the attachment record, upload its content — fed either from Paige's SFTP export files or straight from the Paige API.

Product: paige · Audience: integrator · Time: Half a day for a developer · Last verified: 2026-09-05

Canonical: https://help.ademero.com/paige/integrations/integrate-paige-with-the-business-central-api

**At the end of this guide you'll have the exact sequence of Business Central API calls — and the two ways to get Paige's data into them — to create a draft purchase invoice with the PDF attached for every invoice Paige finishes.**

If you'd rather not write code, the [Power Automate path](/paige/integrations/create-business-central-purchase-invoices-from-paige-with-power-automate) makes the same calls through Microsoft's connector.

## Getting Paige's data

Two sources, same content:

| Source | How | When to prefer it |
| --- | --- | --- |
| **SFTP export files** | Paige writes `<name>.pdf` and `<name>.json` per document; your job polls the folder and reads the JSON (`fields`, `metadata.document_type`, `metadata.pdf_file`) | Simplest; the PDF is already assembled |
| **Paige API** | `GET …/scanJobs/{id}/documentPages` for finished documents, then `…/pages/{pageId}/fieldValues` for values; page images via signed URLs | You want to query rather than watch a folder. Note the API returns page images and per-page text layers, not one merged PDF — see [Integrate your own system with the Paige API](/paige/integrations/integrate-your-own-system-with-the-paige-api). |

Most integrations use SFTP for the PDF and either source for the data. The rest of this guide assumes you have, per invoice, the field values and the PDF bytes.

## Authenticate to Business Central

Register an app in Microsoft Entra ID with the **Dynamics 365 Business Central** `API.ReadWrite.All` application permission, grant it in Business Central under **Microsoft Entra Applications**, and obtain a token with the client-credentials flow. Every call below carries `Authorization: Bearer <token>` and targets:

```
https://api.businesscentral.dynamics.com/v2.0/{tenantId}/{environment}/api/v2.0/companies({companyId})
```

Get the company id once from `GET …/api/v2.0/companies`.

## The four calls

### 1. Create the purchase invoice

```http
POST …/companies({companyId})/purchaseInvoices
Content-Type: application/json

{
  "vendorNumber": "V00123",
  "invoiceDate": "2026-08-28",
  "dueDate": "2026-09-27",
  "vendorInvoiceNumber": "INV-20441"
}
```

Returns `201 Created` with the invoice `id` and its `status: "Draft"`. Use `vendorNumber` (the vendor's No.) or `vendorId`; look the vendor up first with `GET …/vendors?$filter=displayName eq 'Acme Office Supply'` if Paige only gives you the name.

You can also create the invoice and its first line in one request by nesting `purchaseInvoiceLines` in the body (deep insert).

### 2. Add lines

```http
POST …/companies({companyId})/purchaseInvoices({invoiceId})/purchaseInvoiceLines

{
  "lineType": "Account",
  "accountId": "<G/L account id>",
  "description": "Paige – Vendor Invoice",
  "quantity": 1,
  "unitCost": 1284.50
}
```

One line at Paige's `Total` is the simplest. For itemized invoices, send one line per row of Paige's `line_items` table, using `$batch` with `Isolation: snapshot` so a bad line rolls back the lot.

### 3. Create the attachment record

```http
POST …/companies({companyId})/attachments

{
  "parentId": "<invoice id>",
  "parentType": "Purchase Invoice",
  "fileName": "INV-20441.pdf"
}
```

Returns the attachment `id`. In Business Central an attachment is an *incoming document*, which is why it appears under the invoice's Incoming Document FactBox.

### 4. Upload the PDF content

```http
PATCH …/companies({companyId})/attachments({attachmentId})/attachmentContent
Content-Type: application/pdf
If-Match: *

<raw PDF bytes>
```

**What you should see:** `204 No Content`, and the PDF opens from the invoice in Business Central.

## Idempotency and errors

- Before call 1, `GET …/purchaseInvoices?$filter=vendorInvoiceNumber eq 'INV-20441' and vendorNumber eq 'V00123'` and skip if one exists — Paige can export a document twice if someone re-exports by hand.
- Paige's values are strings as printed. Normalize dates to `yyyy-MM-dd` and amounts to numbers before sending; Business Central validates both.
- If you poll SFTP, move processed files to a `processed/` subfolder; if you poll the Paige API, record processed page IDs.

## What's next

- [Create Business Central purchase invoices from Paige with Power Automate](https://help.ademero.com/paige/integrations/create-business-central-purchase-invoices-from-paige-with-power-automate)
- [Integrate your own system with the Paige API](https://help.ademero.com/paige/integrations/integrate-your-own-system-with-the-paige-api)
