|
3 | 3 | # Mindee Client Library for Java |
4 | 4 | Quickly and easily connect to Mindee's API services using Java. |
5 | 5 |
|
6 | | -## Quick Start |
7 | | -Here's the TL;DR of getting started. |
8 | | - |
9 | | -First, get an [API Key](https://developers.mindee.com/docs/create-api-key) |
10 | | - |
11 | | -Include the following maven dependency in your project to use the helper library: |
12 | | -```xml |
13 | | -<dependency> |
14 | | - <artifactId>mindee-api-java</artifactId> |
15 | | - <groupId>com.mindee.sdk</groupId> |
16 | | - <version>${mindee.sdk.version}</version> |
17 | | -</dependency> |
18 | | -``` |
19 | | - |
20 | | -Where `${mindee.sdk.version}` is the version shown here: |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | -## Loading a File and Parsing It |
26 | | -The `MindeeClient` class is the entry point for most of the helper library features. |
27 | | - |
28 | | -## Synchronously Parsing a File |
29 | | -This is the easiest and fastest way to integrate into the Mindee API. |
30 | | - |
31 | | -However, not all products are available in synchronous mode. |
32 | | - |
33 | | -### Global Documents |
34 | | -These classes are available in the `com.mindee.product` package: |
35 | | - |
36 | | -```java |
37 | | -import com.mindee.MindeeClient; |
38 | | -import com.mindee.input.LocalInputSource; |
39 | | -import com.mindee.parsing.common.PredictResponse; |
40 | | -import com.mindee.product.invoice.InvoiceV4; |
41 | | -import java.io.File; |
42 | | -import java.io.IOException; |
43 | | - |
44 | | -public class SimpleMindeeClient { |
45 | | - public static void main(String[] args) throws IOException { |
46 | | - |
47 | | - // Init a new client |
48 | | - MindeeClient mindeeClient = new MindeeClient("my-api-key"); |
49 | | - |
50 | | - // Load a file from disk |
51 | | - LocalInputSource localInputSource = new LocalInputSource( |
52 | | - "/path/to/the/file.ext" |
53 | | - ); |
54 | | - // Parse the file |
55 | | - Document<InvoiceV4> response = mindeeClient.parse( |
56 | | - InvoiceV4.class, |
57 | | - localInputSource |
58 | | - ); |
59 | | - // Print a summary of the parsed data |
60 | | - System.out.println(response.getDocument().toString()); |
61 | | - } |
62 | | -} |
63 | | -``` |
64 | | - |
65 | | -**Note for Region-Specific Documents:** |
66 | | - |
67 | | -Each region will have its own package within the general `com.mindee.product` package. |
68 | | - |
69 | | -For example USA-specific classes will be in the `com.mindee.product.us` package: |
70 | | -```java |
71 | | -import com.mindee.product.us.bankcheck.BankCheckV1; |
72 | | -``` |
73 | | - |
74 | | -### Custom Documents (docTI & Custom APIs) |
75 | | -```java |
76 | | -import com.mindee.MindeeClient; |
77 | | -import com.mindee.PredictOptions; |
78 | | -import com.mindee.input.LocalInputSource; |
79 | | -import com.mindee.parsing.common.PredictResponse; |
80 | | -import com.mindee.product.generated.GeneratedV1; |
81 | | -import com.mindee.http.Endpoint; |
82 | | -import java.io.File; |
83 | | -import java.io.IOException; |
84 | | - |
85 | | -public class SimpleMindeeClient { |
86 | | - public static void main(String[] args) throws IOException { |
87 | | - |
88 | | - // Init a new client |
89 | | - MindeeClient mindeeClient = new MindeeClient("my-api-key"); |
90 | | - |
91 | | - // Init the endpoint for the custom document |
92 | | - Endpoint endpoint = new Endpoint("my-endpoint", "my-account"); |
93 | | - |
94 | | - // Load a file from disk |
95 | | - LocalInputSource localInputSource = new LocalInputSource( |
96 | | - "src/main/resources/invoices/invoice1.pdf" |
97 | | - ); |
98 | | - // Parse the file |
99 | | - Document<GeneratedV1> customDocument = mindeeClient.enqueueAndParse( |
100 | | - localInputSource, |
101 | | - endpoint |
102 | | - // PredictOptions.builder().build(), |
103 | | - ); |
104 | | - } |
105 | | -} |
106 | | -``` |
107 | | - |
108 | | -## Asynchronously Parsing a File |
109 | | -This allows for easier handling of bursts of documents sent. |
110 | | - |
111 | | -Some products are only available asynchronously, check the example code |
112 | | -directly on the Mindee platform. |
113 | | - |
114 | | -### Enqueue and Parse a File |
115 | | -The client library will take care of handling the polling requests for you. |
116 | | - |
117 | | -This is the easiest way to get started. |
118 | | - |
119 | | -```java |
120 | | -import com.mindee.MindeeClient; |
121 | | -import com.mindee.PredictOptions; |
122 | | -import com.mindee.input.LocalInputSource; |
123 | | -import com.mindee.parsing.common.AsyncPredictResponse; |
124 | | -import com.mindee.product.internationalid.InternationalIdV2; |
125 | | -import java.io.File; |
126 | | -import java.io.IOException; |
127 | | - |
128 | | -public class SimpleMindeeClient { |
129 | | - |
130 | | - public static void main(String[] args) throws IOException, InterruptedException { |
131 | | - String apiKey = "my-api-key"; |
132 | | - String filePath = "/path/to/the/file.ext"; |
133 | | - |
134 | | - // Init a new client |
135 | | - MindeeClient mindeeClient = new MindeeClient(apiKey); |
136 | | - |
137 | | - // Load a file from disk |
138 | | - LocalInputSource inputSource = new LocalInputSource(new File(filePath)); |
139 | | - |
140 | | - // Parse the file asynchronously |
141 | | - AsyncPredictResponse<InternationalIdV2> response = mindeeClient.enqueueAndParse( |
142 | | - InternationalIdV2.class, |
143 | | - inputSource |
144 | | - // PredictOptions.builder().build(), |
145 | | - ); |
146 | | - |
147 | | - // Print a summary of the response |
148 | | - System.out.println(response.toString()); |
149 | | - } |
150 | | -} |
151 | | -``` |
152 | | - |
153 | | -### Enqueue and Parse a Webhook Response |
154 | | -This is an optional way of handling asynchronous APIs. |
155 | | - |
156 | | -```java |
157 | | -import com.mindee.MindeeClient; |
158 | | -import com.mindee.input.LocalInputSource; |
159 | | -import com.mindee.input.LocalResponse; |
160 | | -import com.mindee.input.WebhookSource; |
161 | | -import com.mindee.product.internationalid.InternationalIdV2; |
162 | | -import java.io.IOException; |
163 | | - |
164 | | -public class SimpleMindeeClient { |
165 | | - public static void main(String[] args) throws IOException { |
166 | | - |
167 | | - // Init a new client |
168 | | - MindeeClient mindeeClient = new MindeeClient("my-api-key"); |
169 | | - |
170 | | - // Load a file from disk |
171 | | - LocalInputSource localInputSource = new LocalInputSource( |
172 | | - "/path/to/the/file.ext" |
173 | | - ); |
174 | | - // Enqueue the file |
175 | | - String jobId = client.enqueue(InternationalIdV2.class, localInputSource) |
176 | | - .getJob().getId(); |
177 | | - |
178 | | - // Load the JSON string sent by the Mindee webhook POST callback. |
179 | | - // |
180 | | - // Reading the callback data will vary greatly depending on your HTTP server. |
181 | | - // This is therefore beyond the scope of this example. |
182 | | - String jsonData = myHttpServer.getPostBodyAsString(); |
183 | | - LocalResponse localResponse = new LocalResponse(jsonData); |
184 | | - |
185 | | - // Verify the HMAC signature. |
186 | | - // You'll need to get the "X-Mindee-Hmac-Signature" custom HTTP header. |
187 | | - String hmacSignature = myHttpServer.getHeader("X-Mindee-Hmac-Signature"); |
188 | | - boolean isValid = localResponse.isValidHmacSignature( |
189 | | - "obviously-fake-secret-key", hmacSignature |
190 | | - ); |
191 | | - if (!isValid) { |
192 | | - throw new MyException("Bad HMAC signature! Is someone trying to do evil?"); |
193 | | - } |
194 | | - |
195 | | - // You can also use a File object as the input. |
196 | | - //LocalResponse localResponse = new LocalResponse(new File("/path/to/file.json")); |
197 | | - |
198 | | - // Deserialize the response into Java objects |
199 | | - AsyncPredictResponse<InternationalIdV2> response = mindeeClient.loadPrediction( |
200 | | - InternationalIdV2.class, |
201 | | - localResponse |
202 | | - ); |
203 | | - |
204 | | - // Print a summary of the parsed data |
205 | | - System.out.println(response.getDocument().toString()); |
206 | | - } |
207 | | -} |
208 | | -``` |
209 | | - |
210 | | -You can view the source code on [GitHub](https://github.com/mindee/mindee-api-java). |
211 | | - |
212 | | -You can also take a look at the |
213 | | -**[Reference Documentation](https://mindee.github.io/mindee-api-java/)**. |
| 6 | + |
| 7 | + |
| 8 | +## Mindee API Versions |
| 9 | +This client library has support for both Mindee platform versions. |
| 10 | + |
| 11 | +### Latest - V2 |
| 12 | +This is the new platform located here: |
| 13 | + |
| 14 | +https://app.mindee.com |
| 15 | + |
| 16 | +It uses **API version 2**. |
| 17 | + |
| 18 | +Consult the |
| 19 | +**[Latest Documentation](https://docs.mindee.com/integrations/client-libraries-sdk)** |
| 20 | + |
| 21 | + |
| 22 | +### Legacy - V1 |
| 23 | +This is the legacy platform located here: |
| 24 | + |
| 25 | +https://platform.mindee.com/ |
| 26 | + |
| 27 | +It uses **API version 1**. |
| 28 | + |
| 29 | +Consult the |
| 30 | +**[Legacy Documentation](https://developers.mindee.com/docs/java-ocr-getting-started)** |
| 31 | + |
| 32 | +## Additional Information |
| 33 | + |
| 34 | +**[Source Code](https://github.com/mindee/mindee-api-java)** |
| 35 | + |
| 36 | +**[Reference Documentation](https://mindee.github.io/mindee-api-java/)** |
| 37 | + |
| 38 | +**[Feedback](https://feedback.mindee.com/)** |
214 | 39 |
|
215 | 40 | ## License |
216 | 41 | Copyright © Mindee |
|
0 commit comments