Issues with Get started: Form Recognizer REST API 2022-06-30-preview

counterpoint2022 36 Reputation points
2022-07-20T08:14:05.823+00:00

Has anyone try the new preview Rest API? The cURL example described in the document.

I am getting "curl: (6) Could not resolve host: POST". Anyone else run into the same issue? Thanks

curl -v -i POST "https://westus.api.cognitive.microsoft.com/formrecognizer/documentModels/prebuilt-invoice:analyze?api-version=2022-06-30-preview" -H "Content-Type:application/json" -H "Ocp-Apim-Subscription-Key:xxxxxxxxxx" --data-ascii "{'urlSource': 'https://github.com/Azure-Samples/cognitive-services-REST-api-samples/raw/master/curl/form-recognizer/rest-api/invoice.pdf'}"

Azure AI Document Intelligence
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Lu Zhang (AI) 106 Reputation points Microsoft Employee
    2022-07-20T09:05:06.423+00:00

    Hi @counterpoint2022 , can you please check your PowerShell version? You need to install PowerShell version 7.*+ to run this POST request. More detailed instructions are here: https://learn.microsoft.com/en-us/azure/applied-ai-services/form-recognizer/quickstarts/try-v3-rest-api#prerequisites.

    1 person found this answer helpful.

  2. Anonymous
    2022-07-26T11:31:46.753+00:00

    Hi @counterpoint2022 , it looks like you forgot to specify the request method with -X POST. Since POST is provided without an argument switch, curl assumes POST is a host name and the request fails with a DNS error since POST is not a valid Form Recognizer endpoint.

    Since curl supports multiple URLs in a single command the next argument (the valid Form Recognizer endpoint) should succeed (as it does for me on macOS with curl 7.79.1).

    That said, the -X argument is optional when you provide a request body (e.g. with --data-ascii). Curl will automatically default the request method to POST when the body is provided.

    On a side note, your JSON body is technically using invalid JSON syntax, although Form Recognizer will currently accept it. A well-formed JSON string should use double quotes, not single quotes, for object properties.

    The well-formed curl request should look like this:

    curl -i 'https://westus.api.cognitive.microsoft.com/formrecognizer/documentModels/prebuilt-invoice:analyze?api-version=2022-06-30-preview' \  
        -H 'content-type: application/json' \  
        -H "ocp-apim-subscription-key: $MY_FR_KEY" \  
        --data '{"urlSource": "https://github.com/Azure-Samples/cognitive-services-REST-api-samples/raw/master/curl/form-recognizer/rest-api/invoice.pdf"}'
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.