LogoLogo
WebsiteLoginSign up
  • Welcome to Koncile
  • Getting Started
    • Key Koncile features
    • Folders vs. Extraction Templates
    • General fields vs. Repeated fields
  • DATA EXTRACTION APP
    • Set up an Extraction Template
    • Set field format
    • How to write field descriptions
    • Import documents
      • Importing amendments
    • Export data
    • Auto-classify documents
  • Generated fields with AI
  • API Setup
    • API Key generation
    • Swagger
    • API pricing and limits
    • SDK Libraries
      • Python guide
    • File Uploading
    • Task Retrieval
      • Web-hook task retrieval
      • Polling task retrieval
    • Folders
    • Templates
    • Fields
    • Instructions
    • API status codes
    • Bubble Plugin
  • Miscellaneous
    • Q&A
Powered by GitBook
LogoLogo

Useful links

  • Website
  • Login
  • Extraction template library

@Copyright Koncile 2024

On this page

Was this helpful?

Export as PDF
  1. API Setup
  2. Task Retrieval

Polling task retrieval

This example demonstrates how to use the Python requests library to integrate the Koncile API. The script illustrates the following steps:

  1. File Upload: The file is sent to the API via a dedicated endpoint, along with the necessary parameters such as the extraction template and the folder ID.

  2. Retrieval of the Task ID: Once the file is processed, the task ID generated by the API is used to track its status.

  3. Task Processing Monitoring: A polling function periodically checks whether the task is completed before extracting the returned information.

This script can serve as a starting point for integrating Koncile into your automated systems. Be sure to replace placeholder values (e.g., your-api-key, folder-id, template-id, path-to-file) with your own data.

import requests
import time

api_key = "your-api-key"
api_url = "https://api.koncile.ai"

upload_url = f"{api_url}/v1/upload_file/"
fetch_url = f"{api_url}/v1/fetch_tasks_results/"
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={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"])
PreviousWeb-hook task retrievalNextFolders

Last updated 3 months ago

Was this helpful?