Extract API¶
Odoo provides a service to automate the processing of documents of type invoices, expenses or resumes.
The service scans documents using an OCR engine and then uses AI-based algorithms to extract fields of interest such as the total, due date, or invoice lines for invoices, the total, date for expenses, or the name, email, phone number for resumes.
This service is a paid service. Each document processing will cost you one credit. Credits can be bought on iap.odoo.com.
You can either use this service directly in the Accounting, Expense, or Recruitment App or through the API. The Extract API, which is detailed in the next section, allows you to integrate our service directly into your own projects.
Overview¶
The extract API uses the JSON-RPC2 protocol; its endpoint routes are located at
https://extract.api.odoo.com
.
Version¶
The version of the Extract API is specified in the route.
- The latest versions are:
invoices: 122
expenses: 132
applicant: 102
Flow¶
The flow is the same for each document type.
- Call /parse to submit your documents (one call for each document). On success, you receive a
document_token
in the response. - You then have to regularly poll /get_result to get the document’s parsing status.Alternatively, you can provide a
webhook_url
at the time of the call to /parse and you will be notified (via a POST request) when the result is ready.
The HTTP POST method should be used for all of them. A python implementation of the full flow for
invoices can be found here
and a token for integration
testing is provided in the
integration testing section.
Parse¶
Request the processing of a document from the OCR. The route will return a document_token
,
you can use it to obtain the result of your request.
Routes¶
/api/extract/invoice/2/parse
/api/extract/expense/2/parse
/api/extract/applicant/2/parse
Request¶
jsonrpc
(required)see JSON-RPC2
method
(required)see JSON-RPC2
id
(required)see JSON-RPC2
params
account_token
(required)The token of the account from which credits will be taken. Each successful call costs one token.
version
(required)The version will determine the format of your requests and the format of the server response. You should use the latest version available.
documents
(required)The document must be provided as a string in the ASCII encoding. The list should contain only one string. If multiple strings are provided only the first string corresponding to a pdf will be processed. If no pdf is found, the first string will be processed. This field is a list only for legacy reasons. The supported extensions are pdf, png, jpg and bmp.
dbuuid
(optional)Unique identifier of the Odoo database.
webhook_url
(optional)A webhook URL can be provided. An empty POST request will be sent to
webhook_url/document_token
when the result is ready.user_infos
(optional)Information concerning the person sending the document to the extract service. It can be the client or the supplier (depending on the
perspective
). This information is not required in order for the service to work but it greatly improves the quality of the result.user_company_vat
(optional)VAT number of the user.
user_company_name
(optional)Name of the user’s company.
user_company_country_code
(optional)Country code of the user. Format: ISO3166 alpha-2.
user_lang
(optional)The user language. Format: language_code + _ + locale (e.g. fr_FR, en_US).
user_email
(optional)The user email.
purchase_order_regex
(optional)Regex for purchase order identification. Will default to Odoo PO format if not provided.
perspective
(optional)Can be
client
orsupplier
. This field is useful for invoices only.client
means that the user information provided are related to the client of the invoice.supplier
means that it’s related to the supplier. If not provided, client will be used.
{
"jsonrpc": "2.0",
"method": "call",
"params": {
"account_token": string,
"version": int,
"documents": [string],
"dbuuid": string,
"webhook_url": string,
"user_infos": {
"user_company_vat": string,
"user_company_name": string,
"user_company_country_code": string,
"user_lang": string,
"user_email": string,
"purchase_order_regex": string,
"perspective": string,
},
},
"id": string,
}
Notă
The user_infos
parameter is optional but it greatly improves the quality of the result,
especially for invoices. The more information you can provide, the better.
Response¶
jsonrpc
see JSON-RPC2
id
see JSON-RPC2
result
status
The code indicating the status of the request. See the table below.
status_msg
A string giving verbose details about the request status.
document_token
Only present if the request is successful.
status |
status_msg |
---|---|
|
Success |
|
Unsupported version |
|
An error occurred |
|
You don’t have enough credit |
|
Unsupported file format |
|
Server is currently under maintenance, please try again later |
{
"jsonrpc": "2.0",
"id": string,
"result": {
"status": string,
"status_msg": string,
"document_token": string,
}
}
Notă
The API does not actually use the JSON-RPC error scheme. Instead the API has its own error scheme bundled inside a successful JSON-RPC result.
Get results¶
Routes¶
/api/extract/invoice/2/get_result
/api/extract/expense/2/get_result
/api/extract/applicant/2/get_result
Request¶
jsonrpc
(required)see JSON-RPC2
method
(required)see JSON-RPC2
id
(required)see JSON-RPC2
params
version
(required)The version should match the version passed to the /parse request.
document_token
(required)The
document_token
for which you want to get the current parsing status.account_token
(required)The token of the account that was used to submit the document.
{
"jsonrpc": "2.0",
"method": "call",
"params": {
"version": int,
"document_token": int,
"account_token": string,
},
"id": string,
}
Response¶
When getting the results from the parse, the detected field vary a lot depending on the type of document. Each response is a list of dictionaries, one for each document. The keys of the dictionary are the name of the field and the value is the value of the field.
jsonrpc
see JSON-RPC2
id
see JSON-RPC2
result
status
The code indicating the status of the request. See the table below.
status_msg
A string giving verbose details about the request status.
results
Only present if the request is successful.
full_text_annotation
Contains the unprocessed full result from the OCR for the document
status |
status_msg |
---|---|
|
Success |
|
Unsupported version |
|
An error occurred |
|
Server is currently under maintenance, please try again later |
|
The document could not be found |
|
The document has been rejected because it is too small |
|
Unable to get page count of the PDF file |
|
Couldn’t convert the PDF to images |
|
The PDF file is protected by a password |
|
The document contains too many pages |
{
"jsonrpc": "2.0",
"id": string,
"result": {
"status": string,
"status_msg": string,
"results": [
{
"full_text_annotation": string,
"feature_1_name": feature_1_result,
"feature_2_name": feature_2_result,
...
},
...
]
}
}
Common fields¶
feature_result
¶
Each field of interest we want to extract from the document such as the total or the due date are also called features. An exhaustive list of all the extracted features associated to a type of document can be found in the sections below.
For each feature, we return a list of candidates and we spotlight the candidate our model predicts to be the best fit for the feature.
selected_value
(optional)The best candidate for this feature.
selected_values
(optional)The best candidates for this feature.
candidates
(optional)List of all the candidates for this feature ordered by decreasing confidence score.
"feature_name": {
"selected_value": candidate_12,
"candidates": [candidate_12, candidate_3, candidate_4, ...]
}
candidate¶
For each candidate we give its representation and position in the document. Candidates are sorted by decreasing order of suitability.
content
Representation of the candidate.
coords
[center_x, center_y, width, height, rotation_angle]
. The position and dimensions are relative to the size of the page and are therefore between 0 and 1. The angle is a clockwise rotation measured in degrees.page
Page of the original document on which the candidate is located (starts at 0).
"candidate": [
{
"content": string|float,
"coords": [float, float, float, float, float],
"page": int
},
...
]
Invoices¶
Invoices are complex and can have a lot of different fields. The following table gives an exhaustive list of all the fields we can extract from an invoice.
Feature name |
Specifities |
---|---|
|
It contains information about the detected SWIFT code (or BIC). Keys:
Name and city are present only if verified_bic is true. |
|
|
|
|
|
Depending on the value of perspective in the user_infos, this will be the VAT number of the supplier or the client. If perspective is client, it’ll be the supplier’s VAT number. If it’s supplier, it’s the client’s VAT number. |
|
|
|
|
|
Uses |
|
|
|
|
|
Format : YYYY-MM-DD |
|
Same as for |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
feature_result
for the invoice_lines
feature¶
It follows a more specific structure. It is basically a list of dictionaries where each dictionary represents an invoice line. Each value follows a feature_result structure.
"invoice_lines": [
{
"description": feature_result,
"discount": feature_result,
"product": feature_result,
"quantity": feature_result,
"subtotal": feature_result,
"total": feature_result,
"taxes": feature_result,
"total": feature_result,
"unit": feature_result,
"unit_price": feature_result
},
...
]
Expense¶
The expenses are less complex than invoices. The following table gives an exhaustive list of all the fields we can extract from an expense report.
Feature name |
Specifities |
---|---|
|
|
|
|
|
|
|
|
|
|
Applicant¶
This third type of document is meant for processing resumes. The following table gives an exhaustive list of all the fields we can extract from a resume.
Feature name |
Specifities |
---|---|
|
|
|
|
|
|
|
|
Integration Testing¶
You can test your integration by using integration_token as account_token
in the
/parse request.
Using this token put you in test mode and allows you to simulate the entire flow without really parsing a document and without being billed one credit for each successful document parsing.
The only technical differences in test mode is that the document you send is not parsed by the system and that the response you get from /get_result is a hard-coded one.
A python implementation of the full flow for invoices can be found
here
.