-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidate.java
More file actions
38 lines (33 loc) · 1.42 KB
/
Copy pathValidate.java
File metadata and controls
38 lines (33 loc) · 1.42 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
// Validate a ZUGFeRD PDF using the InvoiceXML API.
// Get API key: https://www.invoicexml.com/account/authentication
// Docs: https://www.invoicexml.com/docs/api/validate/zugferd
//
// Dependency: com.squareup.okhttp3:okhttp:4.12.0
import okhttp3.*;
import java.io.File;
public class Validate {
public static void main(String[] args) throws Exception {
// Raw key only, without the "Bearer " prefix (it is added below).
String apiKey = "YOUR_API_KEY";
RequestBody body = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", "invoice.pdf",
RequestBody.create(new File("invoice.pdf"), MediaType.parse("application/pdf")))
.addFormDataPart("version", "2.3.2")
.addFormDataPart("profile", "extended")
.build();
Request request = new Request.Builder()
.url("https://api.invoicexml.com/v1/validate/zugferd")
.header("Authorization", "Bearer " + apiKey)
.post(body)
.build();
try (Response response = new OkHttpClient().newCall(request).execute()) {
String report = response.body().string();
if (!response.isSuccessful()) {
System.err.println("InvoiceXML API error " + response.code() + ": " + report);
System.exit(1);
}
System.out.println(report);
}
}
}