API Basics

The url for DocumentsAPI Production is the following one : https://documents.zelros.com

The url for DocumentsAPI Staging is the following one : https://d2i-staging.zelros.com

Notice that the API is available in a synchronous mode, meaning that in one API call, you can post a document and have the answer. Useful for one by one document’s processing.

Profile
POST Return the analysis of a given file

Authentication

To access our API, you will need an authentication token:

import requests

url = "https://documents.zelros.com/auth/realms/documents/protocol/openid-connect/token"
payload = 'client_id=<YOUR_CLIENT_ID>&client_secret=<YOUR_CLIENT_SECRET>&grant_type=client_credentials'
headers = {
  'Content-Type': 'application/x-www-form-urlencoded'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))

which returns the following json response:

{
    "access_token": "TOKEN",
    "refresh_token": "REFRESH_TOKEN",
    "token_type": "bearer",
    ...
}

The obtained token, access_token, has to be placed into the authorization tag, like this : Authorization: Bearer <TOKEN>.

You can also refresh your token to extend its lifetime, by sending the previous request with an extra refresh_token parameter, with your REFRESH_TOKEN value, and updating the grant_type value to refresh_token.

API Call

Request parameters:

  • file document to analyze

  • type* type of document sent

Documents are accepted in jpeg, jpg, png, and pdf.

A parameter type or document_tags can be used to give an information about the document sent.

Example

import requests (1)
import json

file_path = '<YOUR_FILE_PATH>'
token = '<YOUR_TOKEN>'

resp = requests.post(
    'https://documents.zelros.com/api/analyze', data={'document_tags': 'CAR_REGISTRATION' },
    files={'file':  open(file_path, 'rb')}, (2)
    headers={'Authorization': f'Bearer {token}'}
) (3)

body = json.loads(resp.content.decode('utf8'))
print(body)
1 Library import
2 File conversion into binary
3 Launch request

*: If no parameter is provided, the document goes through a classification brick that will determine it before the analysis. This option works for a certain list of document types described below.

Full code

The full code to use Documents API is available here:

import requests
import json
import time

file_path = './document.pdf'

# AuthN to the API

url = "https://documents.zelros.com/auth/realms/documents/protocol/openid-connect/token"
payload = 'client_id=<YOUR_CLIENT_ID>&client_secret=<YOUR_CLIENT_SECRET>&grant_type=client_credentials'
headers = {
  'Content-Type': 'application/x-www-form-urlencoded'
}
response = requests.request("POST", url, headers=headers, data = payload)
JSON_auth = json.loads(response.content.decode('utf8'))

token = JSON_auth["access_token"]
print('token','\n', token,'\n')

#  Post the document

print("wait a couple seconds... ",'\n')
start = time.time()
resp = requests.post(
    'https://documents.zelros.com/api/analyze',
    files={'file':  open(file_path, 'rb')},
    headers={'Authorization': f'Bearer {token}'}
)

body = json.loads(resp.content.decode('utf8'))

end = time.time()

print(body,'\n')
print("elasped time for sending + retrieving the document : ",end - start, "seconds")