Query

Checks the status of a file. It is recommended to wait at least 2 seconds between Query calls. Calling the Query method more frequently than this will not have any impact on application performance. The method can be called with a Post or Get request to the following URL:

[POST][GET]  https://azure.leadtools.com/api/Query

Request Specific Parameters

Additional parameters available are listed below.

Parameter Description Accepted Values
id Unique identifier corresponding to an uploaded file. A valid GUID

Status Codes

The following status codes will be returned when the method is called:

Status Description
200 The Query request completed successfully
400 The request was not valid for one of the following reasons:

• Invalid GUID was provided
401 The AppID/Password combination is not valid, or does not correspond with the GUID provided.
500 There was an internal error processing your request.

Returns

A successful request will return a JSON Object with the following format:

{ 
   "FileStatus":, 
   "RequestData": [ 
   ] 
} 

The RequestData property will be empty unless the File Status value is 200. The possible File Statuses are as follows:

File Status Description
100 The file is currently being processed.
122 The file hasn't been set to run. This is for files that have been uploaded via the UploadFile API call and haven't had the Run method called on them.
123 The file is currently undergoing verification. This is for files that have been recently uploaded via the UploadFile API call, or from one of the single service Conversion/Recognition calls. If the UploadFile API method was called originally, the file's worker status will be set to 122 after the verification process completes successfully. If one of the Recognition/Conversion single service API methods were called, then the file's worker status will be set to 100 and processing will begin on the file.
200 The file has finished processing successfully. The RequestData property will contain a serialized list of all the pertinent information for the request(s) that were made against the file. For the JSON structure for the different request objects, refer to the Common Request Parameters and Return Objects section
500 There was an internal error processing the file.
501 The file has been deleted. Files/data will be deleted automatically after 24 hours, or if the DeleteRequest API method is called.
502 The file has been rejected. Files will be rejected if they fail the verification process. Rejected files will be deleted automatically after 24 hours, or if the DeleteRequest API method is
600 Processing of the file has been aborted because there are not enough pages remaining in the application.

Examples

JavaScript (Node.js)
C#
Python
PHP
Perl
//This sample uses the Request NodeJs library. 
const request = require('request'); 
 
var servicesUrl = "https://azure.leadtools.com/api/"; 
 
var requestID = '00000000-0000-0000-0000-000000000000'; 
 
function queryServices(requestID){ 
    //Function to query the status of a request.  If the request has not yet finished, this function will recursively call itself until the file has finished. 
    var queryUrl = servicesUrl +"Query?id=" + requestID; 
    request.post(getRequestOptions(queryUrl), async function (error, response, body){ 
        var results = JSON.parse(body); 
        if(!error && results['FileStatus']!=100 && results['FileStatus']!=123){ 
 
            console.log("File finished processing with return code: " + response.statusCode); 
            if(results['FileStatus']!=200){ 
                return; 
            } 
            console.log("Results: \n"); 
            console.log(results['RequestData']); 
        }else{ 
            //The file has not yet finished processing. 
            await function(){ 
                return new Promise(resolve=> setTimeout(resolve, 5000)); //Sleep for 5 seconds before trying again 
            } 
            queryServices(requestID); //Call the method again. 
        } 
    }); 
} 
 
function getRequestOptions(url){ 
    //Function to generate and return HTTP request  options. 
    var requestOptions ={ 
        url: url, 
        headers: { 
            'Content-Length' : 0 
        }, 
        auth: { 
            user:"Enter Application ID", 
            password:"Enter Application Password" 
        } 
    }; 
    return requestOptions; 
} 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Threading; 
using System.Net; 
using System.Net.Http; 
using System.Net.Http.Headers; 
using Newtonsoft.Json.Linq; 
 
namespace Azure_Code_Snippets.DocumentationSnippets 
{ 
   class CloudServices_Query_Demo 
   { 
      private string hostedServicesUrl = "https://azure.leadtools.com/api/"; 
 
      public void Run() 
      { 
         HttpClient client = InitClient(); 
         string id = Guid.Empty.ToString(); 
         Query(id, client); 
      } 
      private async Task Query(string id, HttpClient client) 
      { 
         string queryUrl = string.Format("Query?id={0}", id.ToString()); 
         var result = await client.PostAsync(queryUrl, null); 
         var returnedContent = await result.Content.ReadAsStringAsync(); 
         var returnedData = JObject.Parse(returnedContent); 
         if ((int)returnedData.SelectToken("FileStatus") == 100 || (int)returnedData.SelectToken("FileStatus") == 123) 
         { 
            //The file is still being processed -- we will sleep the current thread for 5 seconds before trying again. 
            await Task.Delay(5000); 
            await Query(id, client); 
         } 
 
         Console.WriteLine("File has finished processing with return code: " + returnedData.SelectToken("FileStatus")); 
         if ((int)returnedData.SelectToken("FileStatus") != 200) 
            return; 
 
         Console.WriteLine("Returned Content: " + returnedData.SelectToken("RequestData")); 
      } 
 
      private HttpClient InitClient() 
      { 
         string AppId = "Enter Application ID"; 
         string Password = "Enter Application Password"; 
 
         HttpClient client = new HttpClient(); 
         client.BaseAddress = new Uri(hostedServicesUrl); 
         client.DefaultRequestHeaders.Accept.Clear(); 
         client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); 
 
         string authData = string.Format("{0}:{1}", AppId, Password); 
         string authHeaderValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(authData)); 
         client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authHeaderValue); 
 
         return client; 
      } 
   } 
} 
#This sample uses the requests python library. 
 
import requests, sys, time 
 
servicesUrl = 'https://azure.leadtools.com/api/' 
 
requestID = '00000000-0000-0000-0000-000000000000'; 
 
#Your application ID. 
appId = "Enter Application ID"; 
 
#Your application password. 
password = "Enter Application Password"; 
 
baseQueryUrl = '{}Query?id={}' 
formattedQueryUrl = baseQueryUrl.format(servicesUrl, requestID) 
 
while True : #Poll the services to determine if the request has finished processing 
    request = requests.post(formattedQueryUrl, auth=(appId, password)) 
    returnedData = request.json(); 
    if returnedData['FileStatus'] != 100 and returnedData['FileStatus'] != 123: 
        break 
    time.sleep(5) 
 
print("File finished processing with file status: " + str(returnedData['FileStatus']) + "\n") 
<?php 
 
    $servicesBaseUrl = "https://azure.leadtools.com/api/"; 
 
    $requestID = '00000000-0000-0000-0000-000000000000'; 
 
    $queryUrl = "%sQuery?id=%s"; 
    $queryUrl = sprintf($queryUrl, $servicesBaseUrl, $requestID); 
    $requestOptions = GeneratePostOptions($queryUrl); 
    while(true){ //Poll the services to determine if the request has finished processing. 
        $request = curl_init(); 
        curl_setopt_array($request, $queryRequestOptions); //Set the request URL 
        if(!$results = curl_exec($request)){ 
            echo "There was an error querying the services \n\r"; 
            echo $results; 
            curl_close($request); 
            exit; 
        } 
        curl_close($request); 
        $decodedResponse = json_decode($results); 
        $fileStatus= $decodedResponse -> {'FileStatus'}; 
 
        if($fileStatus != 100 && $fileStatus != 123){ 
            //The file has finished processing 
            break; 
        } 
        sleep(5); //If the file hasn't finished processing, we will wait 5 seconds before checking again. 
    } 
 
    echo "File finished processing with file status: " . $fileStatus . "\n\r"; 
 
 
    function GeneratePostOptions($url) 
    { 
        $appId = "Enter Application ID"; 
        $password = "Enter Application Password"; 
 
        $headers = array( 
            "Content-Length : 0" 
            ); 
        $postOptions = array( 
            CURLOPT_POST => 1, 
            CURLOPT_URL => $url, 
            CURLOPT_FRESH_CONNECT => 1, 
            CURLOPT_RETURNTRANSFER => 1, 
            CURLOPT_USERPWD => "$appId:$password", 
            CURLOPT_FORBID_REUSE => 1, 
            CURLOPT_HTTPHEADER => $headers 
        ); 
        return $postOptions; 
    } 
 
?> 
use base 'HTTP::Message'; 
use LWP::UserAgent (); 
 
my $servicesUrl = "https://azure.leadtools.com/api/"; 
 
my $requestID = '00000000-0000-0000-0000-000000000000'; 
 
my $appId = 'Enter Application ID'; 
my $password = 'Enter Application Password'; 
my $headers = HTTP::Headers->new( 
    Content_Length => 0 
); 
$headers->authorization_basic($appId, $password); 
 
#The User Agent to be used when making requests 
my $ua = LWP::UserAgent->new; 
 
my $queryUrl = $servicesUrl . 'Query?id=' . $requestID; 
while(true){ 
    $request = HTTP::Request->new(POST => $queryUrl, $headers); 
    $response = $ua->request($request); 
 
    $returnedData = parse_json($response->decoded_content); 
    if($returnedData->{'FileStatus'} != 100 and $returnedData->{'FileStatus'} != 123){ 
        last; 
    } 
    sleep(5); 
} 
 
print("File finished processing with file status: " . $returnedData->{'FileStatus'} . "\n"); 

See Also

Resources

Legal

Help Version 21.0.2021.9.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.