Asynchronous
For ease of use we recommend using the sync requests. However, if you have large documents or if you want to avoid timeouts, you can use asynchronous requests.
Setting up Asynchronous Requests​
To use asynchronous requests, set the asynchronous parameter to True in the payload:
{
"analyse_type": ["risk"],
"asynchronous": true
}
Retrieving Results​
After the document is submitted for analysis, a verification token will be returned in the response. This token can be used to retrieve the analysis results later.
The results are available at the following endpoint:
note
The results are available after the document has been processed, and are deleted after 60 minutes.
Example​
warning
If the response is not ready to be retrieved, you will receive an error message. We recommend fetching the results every 30 seconds until you receive a successful response.
- Python
- Javascript
import requests
import json
import time
# Configuration
API_KEY = "YOUR_API_KEY_HERE"
FILE_PATH = "sample.pdf"
# Step 1: Submit document for async analysis
url_analyse = "https://api-v2.finovox.com/analyse"
headers = {"api-key": API_KEY}
payload = {
"analyse_type": ["risk"],
"asynchronous": True # Enable async mode
}
with open(FILE_PATH, "rb") as f:
files = [("file", ("sample.pdf", f.read()))]
data = {"payload": json.dumps(payload)}
response = requests.post(url_analyse, headers=headers, files=files, data=data, timeout=150)
result = response.json()
print("Document submitted. Token:", result["retrieve_token"])
# Step 2: Poll for results every 30 seconds
url_retrieve = "https://api-v2.finovox.com/retrieve"
retrieve_data = {"retrieve_token": result["retrieve_token"]}
while True:
response = requests.post(url_retrieve, headers=headers, json=retrieve_data, timeout=150)
if response.status_code == 200:
# Analysis complete
results = response.json()
print("Analysis complete:", results)
break
else:
# Still processing, wait 30 seconds
print("Processing... checking again in 30s")
time.sleep(30)
// npm install axios form-data
const fs = require('fs')
const axios = require('axios')
const FormData = require('form-data')
// Configuration
const API_KEY = 'YOUR_API_KEY_HERE'
const FILE_PATH = 'sample.pdf'
// Step 1: Submit document for async analysis
const url_analyse = 'https://api-v2.finovox.com/analyse'
const form = new FormData()
form.append('file', fs.createReadStream(FILE_PATH))
form.append('payload', JSON.stringify({
analyse_type: ['risk'],
asynchronous: true // Enable async mode
}))
axios.post(url_analyse, form, {
headers: {
'api-key': API_KEY,
...form.getHeaders()
},
timeout: 150000
}).then(response => {
const result = response.data
console.log('Document submitted. Token:', result.retrieve_token)
// Step 2: Poll for results every 30 seconds
const url_retrieve = 'https://api-v2.finovox.com/retrieve'
const retrieveData = { retrieve_token: result.retrieve_token }
const checkResults = async () => {
while (true) {
const retrieveResponse = await axios.post(url_retrieve, retrieveData, {
headers: { 'api-key': API_KEY },
timeout: 150000,
validateStatus: () => true
})
if (retrieveResponse.status === 200) {
// Analysis complete
console.log('Analysis complete:', retrieveResponse.data)
break
} else {
// Still processing, wait 30 seconds
console.log('Processing... checking again in 30s')
await new Promise(resolve => setTimeout(resolve, 30000))
}
}
}
checkResults()
})