How to call Form-recongnizer API version 2023-02-28 -layout model

John Tsz Kin WONG (External) 20 Reputation points
2023-04-04T09:53:22.3366667+00:00

Do you have any sample code for me to call the API version 2023-02-28 - layout model to prcoess my data?

Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
1,443 questions
0 comments No comments
{count} votes

Accepted answer
  1. YutongTie-MSFT 46,996 Reputation points
    2023-04-04T18:43:05.6933333+00:00

    Hello @John Tsz Kin WONG (External) Thanks for reaching out to us, please be aware of that 2023-02-28-preview capabilities are currently only available in the following regions:

    • West Europe
    • West US2
    • East US

    I am sharing a Python sample for your reference, you can get sample in more languages at the bottom of the page - https://westus.dev.cognitive.microsoft.com/docs/services/form-recognizer-api-2023-02-28-preview/operations/AnalyzeDocument

    ########### Python 2.7 #############
    import httplib, urllib, base64
    
    headers = {
        # Request headers
        'Content-Type': 'application/json',
        'Ocp-Apim-Subscription-Key': '{subscription key}',
    }
    
    params = urllib.urlencode({
        # Request parameters
        'pages': '{string}',
        'locale': '{string}',
        'stringIndexType': 'textElements',
    })
    
    try:
        conn = httplib.HTTPSConnection('westus.api.cognitive.microsoft.com')
        conn.request("POST", "/formrecognizer/documentModels/{modelId}:analyze?api-version=2023-02-28-preview&%s" % params, "{body}", headers)
        response = conn.getresponse()
        data = response.read()
        print(data)
        conn.close()
    except Exception as e:
        print("[Errno {0}] {1}".format(e.errno, e.strerror))
    
    ####################################
    
    ########### Python 3.2 #############
    import http.client, urllib.request, urllib.parse, urllib.error, base64
    
    headers = {
        # Request headers
        'Content-Type': 'application/json',
        'Ocp-Apim-Subscription-Key': '{subscription key}',
    }
    
    params = urllib.parse.urlencode({
        # Request parameters
        'pages': '{string}',
        'locale': '{string}',
        'stringIndexType': 'textElements',
    })
    
    try:
        conn = http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')
        conn.request("POST", "/formrecognizer/documentModels/{modelId}:analyze?api-version=2023-02-28-preview&%s" % params, "{body}", headers)
        response = conn.getresponse()
        data = response.read()
        print(data)
        conn.close()
    except Exception as e:
        print("[Errno {0}] {1}".format(e.errno, e.strerror))
    
    ####################################
    
    

    More samples at the bottom - User's image

    I hope this helps. Regards, Yutong -Please kindly accept the answer and vote 'Yes' if you feel helpful to support the community, thanks a lot.


0 additional answers

Sort by: Most helpful