-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract-json.html
More file actions
38 lines (31 loc) · 1.21 KB
/
Copy pathextract-json.html
File metadata and controls
38 lines (31 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<meta charset="utf-8">
<title>Extract ZUGFeRD JSON with InvoiceXML API</title>
<!--
Get API key: https://www.invoicexml.com/account/authentication
Docs: https://www.invoicexml.com/docs/api/extract/json
WARNING: do not ship API keys in production browser code. Proxy through
your own backend so the key stays server-side.
-->
<h1>Extract ZUGFeRD data as JSON</h1>
<input type="file" id="file" accept="application/pdf">
<button id="run">Extract</button>
<pre id="output"></pre>
<script>
// Raw key only, without the "Bearer " prefix (it is added below).
const apiKey = 'YOUR_API_KEY';
document.getElementById('run').addEventListener('click', async () => {
const file = document.getElementById('file').files[0];
if (!file) return alert('Choose a PDF first.');
const form = new FormData();
form.append('file', file);
const response = await fetch('https://api.invoicexml.com/v1/extract/json', {
method: 'POST',
headers: { Authorization: 'Bearer ' + apiKey },
body: form,
});
const json = await response.text();
document.getElementById('output').textContent =
response.ok ? json : `InvoiceXML API error ${response.status}: ${json}`;
});
</script>