Search code examples
c#azureazure-form-recognizer

MS Form Recognizer API - Analyze document - Result ID


I am trying to use the AZ Form Recognizer API from the Link Here and I am unable to do the following -

  1. Attach PDF's in the testing console. How can we do this?

  2. I tried the same API from Postman and attached the PDF for the sake of moving on and now I expected the result to have some 'result ID' that I can use later in my call to API - Analyze result.

The documents here are not indicative of where the result id should be gathered from.


Solution

  • This API Link1 does not support attaching PDF file even if you select application/pdf, Refer below:-

    For application/json urlSource: "string" for request body paramater is present:-

    enter image description here

    But for application/pdf there's no request body parameter present:-

    enter image description here

    So In order to Analyze Invoice with PDF with the above link, Use application/json and enter your invoice github link and the call will be successful you will also receive result ID in the output, Refer below:-

    API LINK2 of Analyze Document:-

    As my Form recognizer resource is in Australia I have selected Australia as a region from this API Link3 and entered the parameters like below:-

    enter image description here

    Output:-

    enter image description here

    Call:-

        Host 
        Name- australiaeast.api.cognitive.microsoft.com
        
        Query paramaters
        
        modelId prebuilt invoice
        
        Headers
        
        Content-Type application/json
        Ocp-Apim-subscription-Key <your API key>
        
        Request body
        
        {
          "urlSource": "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-invoice.pdf"
        }
    

    HTTP Request:-

    POST https://australiaeast.api.cognitive.microsoft.com/formrecognizer/documentModels/prebuilt-invoice:analyze?api-version=2022-08-31 HTTP/1.1
    Host: australiaeast.api.cognitive.microsoft.com
    Content-Type: application/json
    Ocp-Apim-Subscription-Key: ••••••••••••••••••••••••••••••••
    
    {
      "urlSource": "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-invoice.pdf"
    }
    

    Response:-

    Operation-Location: https://australiaeast.api.cognitive.microsoft.com/formrecognizer/documentModels/prebuilt-invoice/analyzeResults/3305e6d3-2207-4727-8ffa-b04bb536c344?api-version=2022-08-31
    x-envoy-upstream-service-time: 455
    apim-request-id: 3305e6d3-2207-4727-8ffa-b04bb536c344
    Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
    x-content-type-options: nosniff
    x-ms-region: Australia East
    Date: Wed, 17 May 2023 05:50:28 GMT
    Content-Length: 0
    

    In the above response:- 3305e6d3-2207-4727-8ffa-b04bb536c344 is the Result ID as given in this Rest API

    Now you can call the GetAnalyze Result API from this link.

    You can add the PDF file in postman request body form-data and call this API Refer below:-

    enter image description here

    enter image description here

    POST https://australiaeast.api.cognitive.microsoft.com/formrecognizer/v2.0/prebuilt/receipt/analyze
    
    Content-Type:application/pdf
    Ocp-Apim-Subscription-Key:6e3xxxxxxxxxx
    
    Body
    form-data
    Source <file>