API et Intégrations

Comment fonctionne l’intégration à l’API koncile

File uploading

curl api.koncile.ai/buffer/upload_file/ \\
  -H "Content-Type: application/json" \\
  -H "Authorization: Bearer $API_KEY" \\
  -d '{
	  "config_id": $Use-case-id,
	  "class_id": $file-type-id
   }' \\
  -F "files=@test.txt"

Returned schemas

{
	task_ids: ["EOBdOSUX4Uv57YWsLYc4JQ", "cUrsd2ClWXa8vzupWQ2zGQ"]
}

Tasks retrieval

curl api.koncile.ai/tasks/{task_id}/ \\
  -H "Content-Type: application/json" \\
  -H "Authorization: Bearer $API_KEY"

Returned schemas

{
	"status": DONE | DUPLICATE | IN PROGRESS | FAILED,
	"document_id": ID,
	"status_message": "",
	"General_fields":
		{
			"Date" : "05/08/20222",
			"Price" : "23$",
			"Supplier name" : "Koncile",
		}
	,
	"Line_fields":
		{
			"Date" : ["05/08/2022", "05/09/2022", "03/02/2023"],
			"Price" : ["23$", "12$", "5$"],
			"Supplier name" : ["Koncile", "Koncile", "Koncile"]
		}
}

Exemple python code

import requests
import time

api_key = "your-api-key"

upload_url = "<http://localhost:8000/buffer/upload_file/>"
fetch_url = "<http://localhost:8000/tasks/>"
params = {"config_id": 'use-case-id', "class_id": 'file-type-id'}
file_path = './path-to-file'
headers = {
    "accept": "application/json",
    "Authorization": f"Bearer {api_key}"
}
files = [
    ('files', open(file_path, 'rb')),
]
response = requests.post(upload_url, params=params, headers=headers, files=files)

if response.status_code != 200:
    print(response.status_code)
    print(response.json())
    exit(1)

task_id = response.json()["task_ids"][0]

def poll_until_done(task_id, headers):
    while True:
        response = requests.get(f"{fetch_url}{task_id}", headers=headers)
        status = response.json()["status"]
        if status != "IN PROGRESS":
            return response
        print("Task in progress")
        time.sleep(2)

response = poll_until_done(task_id, headers)
print(response.json()["status"])
print(response.json()["status_message"])

print(response.json()["General_fields"])
print(response.json()["Line_fields"])

Swagger

https://api.koncile.ai/documentation