6. Get results
Last updated
Last updated
POST
/getBatchResults
This endpoint retrieves the results for a specific batch of documents. By providing the extractionId
and batchId
, you can obtain the processed data or the current status of the batch, indicating whether the processing is complete or still in progress.
When also providing the fileId
, the endpoint filters the results to only that file.
For a complete and interactive set of API requests, please refer to our Postman Integrationcollection.
https://api.extracta.ai/api/v1
Name | Value |
---|---|
Name | Type | Required | Description |
---|---|---|---|
{
"extractionId": "extractionId",
"batchId": "batchId",
"fileId": "fileId" // optional
}
To avoid rate-limiting, please ensure a delay of 2 seconds between consecutive requests to this endpoint.
const axios = require('axios');
/**
* Retrieves the results for a specific batch of documents.
*
* @param {string} token - The authorization token for API access.
* @param {string} extractionId - The unique identifier for the extraction.
* @param {string} batchId - The unique identifier for the batch.
* @param {string} [fileId] - The unique identifier for the file (optional).
* @returns {Promise<Object>} The promise that resolves to the batch results.
*/
async function getBatchResults(token, extractionId, batchId, fileId) {
const url = "https://api.extracta.ai/api/v1/getBatchResults";
try {
// Constructing the request payload
const payload = {
extractionId,
batchId
};
// Adding fileId to the payload if provided
if (fileId) {
payload.fileId = fileId;
}
const response = await axios.post(url, payload, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
}
});
// Handling response
return response.data; // Directly return the parsed JSON response
} catch (error) {
// Handling errors
throw error.response ? error.response.data : new Error('An unknown error occurred');
}
}
async function main() {
const token = 'apiKey';
const extractionId = 'extractionId';
const batchId = 'batchId';
const fileId = 'optionalFileId'; // Set this to null or undefined if you don't want to include it
try {
const batchResults = await getBatchResults(token, extractionId, batchId, fileId);
console.log("Batch Results:", batchResults);
} catch (error) {
console.error("Failed to retrieve batch results:", error);
}
}
main();
import requests
def get_batch_results(token, extraction_id, batch_id, file_id=None):
"""
Retrieves the results for a specific batch of documents.
:param token: The authorization token for API access.
:param extraction_id: The unique identifier for the extraction.
:param batch_id: The unique identifier for the batch.
:param file_id: The unique identifier for the file (optional).
:return: The batch results as a Python dictionary.
"""
url = "https://api.extracta.ai/api/v1/getBatchResults"
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {token}'
}
payload = {
'extractionId': extraction_id,
'batchId': batch_id
}
# Adding file_id to the payload if provided
if file_id:
payload['fileId'] = file_id
response = requests.post(url, json=payload, headers=headers)
# Check if the request was successful
if response.status_code == 200:
return response.json() # Return the parsed JSON response
else:
# Handle errors or unsuccessful responses
response.raise_for_status()
# Example usage
if __name__ == "__main__":
token = 'apiKey'
extractionId = 'extractionId'
batchId = 'batchId'
fileId = 'optionalFileId' # Set this to None if you don't want to include it
try:
batch_results = get_batch_results(token, extractionId, batchId, fileId)
print("Batch Results:", batch_results)
except Exception as e:
print("Failed to retrieve batch results:", e)
<?php
/**
* Retrieves the results for a specific batch of documents.
*
* @param string $token The authorization token for API access.
* @param string $extractionId The unique identifier for the extraction.
* @param string $batchId The unique identifier for the batch.
* @param string|null $fileId The unique identifier for the file (optional).
* @return mixed The batch results or an error message.
*/
function getBatchResults($token, $extractionId, $batchId, $fileId = null) {
$url = 'https://api.extracta.ai/api/v1/getBatchResults';
// Initialize cURL session
$ch = curl_init($url);
// Prepare the payload
$payload = [
'extractionId' => $extractionId,
'batchId' => $batchId
];
// Adding fileId to the payload if provided
if ($fileId !== null) {
$payload['fileId'] = $fileId;
}
$payload = json_encode($payload);
// Set cURL options
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $token,
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
try {
// Execute cURL session
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
throw new Exception('Curl error: ' . curl_error($ch));
}
return $response;
} catch (Exception $e) {
// Handle exceptions or errors here
return 'Error: ' . $e->getMessage();
} finally {
// Always close the cURL session
curl_close($ch);
}
}
// Example usage
$token = 'apiKey';
$extractionId = 'extractionId';
$batchId = 'batchId';
$fileId = 'optionalFileId'; // Set this to null if you don't want to include it
try {
$batchResults = getBatchResults($token, $extractionId, $batchId, $fileId);
echo $batchResults;
} catch (Exception $e) {
echo "Failed to retrieve batch results: " . $e->getMessage();
}
?>
{
"extractionId": "extractionId",
"batchId": "batchId",
"files": [
{
"fileName": "File 2.png",
"status": "processed",
"result": {
"last_job_position": "Full-Stack Developer",
"name": "John",
"phone_number": "000 000 000",
"surname": "Smith",
"years_of_experience": "6"
},
"url": "fileUrl"
},
...
]
}
{
"extractionId": "extractionId",
"batchId": "batchId",
"fileId": "fileId",
"files": [
{
"fileName": "File 1.png",
"status": "processed",
"result": {
"last_job_position": "Full-Stack Developer",
"name": "John",
"phone_number": "000 000 000",
"surname": "Smith",
"years_of_experience": "6"
},
"url": "fileUrl"
}
]
}
{
"extractionId": "extractionId",
"batchId": "batchId",
"fileId": "fileId", // optional
"status": "waiting"
}
{
"error": "Invalid request"
}
Content-Type
application/json
Authorization
Bearer <token>
extractionId
string
true
The ID of the extraction
batchId
string
true
The ID of the batch
fileId
string
false
The ID of the file