Azure AI | Document Intelligence | REST API | Authentication

Avni Bhatt 120 Reputation points
2023-12-06T12:58:05.5+00:00

Hi Team,

I am trying to use the Document Intelligence Services REST API for a custom mode. The API works great in the "Try in out" mode. However, I want to use it programmatically via API. I am unable to figure out the Authentication piece, what all needs to be passed via calling API from Postman . I implemented it successfully in C# SDK and passed 2 parameters there - endpoint and key.

But help is requested to identify the same in REST API.

EDIT: I tried below but it throws error:

Call Details:

Endpoint:

https://<Document intelligence URL>/documentintelligence/documentModels/<ID of Custom extraction model>:analyze?_overload=analyzeDocument&api-version=2023-10-31-preview&Ocp-Apim-Subscription-Key=<KEY associated to endpoint>&urlSource=<PATH to PDF from azure blob storage>

Error:

{
    "statusCode": 401,
    "message": "Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired."
}

Note: the combination of endpoint and the key works from C# SDK as well as the Document intelligence studio.

Avni Bhatt

Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
2,100 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,598 questions
{count} vote

Accepted answer
  1. dupammi 8,615 Reputation points Microsoft External Staff
    2023-12-07T10:49:45.05+00:00

    Hi @Avni Bhatt ,

    Thank you for using the Microsoft Q&A.

    Regarding your error while using the REST API, Kindly issue the POST request followed by GET request in the postman to the document intelligence custom model. Once the POST request was done in the Postman / curl command(in cmd window), we get the "Operation Location", from where we can check the model analysis results. Kindly use this "Operation Location" URL in the GET request in postman. Please also provide the API key , content type etc in the GET request as well and click on "SEND" button in postman.

    Note : The headers, body in the postman are important ones to configure while sending the POST request followed by the GET request. POST request is used to submit the forms inside your Blob container to the custom model (URL mentioned in POST request). Then the GET request is used to fetch the model results.

    Also check on below in your postman or CURL command:

    Screenshots from Postman :

    POST:
    2023-12-07 16_02_15-Post data - My Workspace

    Inside the "Body" of POST request in postman, please give your BLOB container SAS URL, as shown below :
    User's image

    Take a note of the "Operation Location" from above step, after clicking on the "SEND" button.  

    **GET
    **
    2023-12-07 16_14_26-Get data - My Workspace

    I hope this helps! Thanks!

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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