1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "mode": "inline",
12 "documents": [
13 {
14 "id": "invoice-1001",
15 "contentType": "text/plain",
16 "fileName": "invoice-1001.txt",
17 "text": "Invoice Number: INV-1001\nInvoice Date: 2026-09-20\nSupplier: Northwind Parts Ltd\nTotal Due: 1240.50\nCurrency: GBP"
18 }
19 ],
20 "jsonSchema": {
21 "type": "object",
22 "additionalProperties": false,
23 "required": [
24 "invoiceNumber",
25 "invoiceDate",
26 "supplier",
27 "totalDue",
28 "currency"
29 ],
30 "properties": {
31 "currency": {
32 "type": "string",
33 "enum": [
34 "GBP",
35 "EUR",
36 "USD"
37 ]
38 },
39 "invoiceDate": {
40 "type": "string",
41 "format": "date"
42 },
43 "invoiceNumber": {
44 "type": "string"
45 },
46 "supplier": {
47 "type": "string"
48 },
49 "totalDue": {
50 "type": "number",
51 "minimum": 0
52 }
53 }
54 },
55 "fieldConfig": {
56 "invoiceNumber": {
57 "aliases": [
58 "Invoice Number",
59 "Invoice No"
60 ],
61 "description": "Unique invoice identifier"
62 },
63 "totalDue": {
64 "aliases": [
65 "Total Due",
66 "Amount Due"
67 ],
68 "description": "Final amount payable"
69 }
70 }
71};
72
73
74const run = await client.actor("first_watch/pdf-document-structured-json-extraction").call(input);
75
76
77console.log('Results from dataset');
78console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
79const { items } = await client.dataset(run.defaultDatasetId).listItems();
80items.forEach((item) => {
81 console.dir(item);
82});
83
84