You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Edit 5/24/2024 5:50 PM
I have tried running the example from the legacy 3.1 documents and do not run into this issue. It seems this is only an issue with the v4.0 documentation.
Original
I have tried running the example from the v 4.0 documentation and received this error.
I am running Node 16.13.0 on Windows 10.
I'm not sure what I am doing wrong or if the example has faulty code. Any guidance or resolution would be helpful. Thank you.
Please provide us with the following information:
This issue is for a: (mark with an x)
- [x] bug report -> please search issues before submitting
- [ ] feature request
- [x] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)
constDocumentIntelligence=require("@azure-rest/ai-document-intelligence").default,{ getLongRunningPoller, isUnexpected }=require("@azure-rest/ai-document-intelligence");const{ AzureKeyCredential }=require("@azure/core-auth");const{ config }=require("dotenv")config()// sample documentconstinvoiceUrl="https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-invoice.pdf"// set `<your-key>` and `<your-endpoint>` variables with the values from the Azure portal.constkey=process.env.KEY;constendpoint=process.env.ENDPOINT;asyncfunctionmain(){constclient=DocumentIntelligence(endpoint,newAzureKeyCredential(key));constinitialResponse=awaitclient.path("/documentModels/{modelId}:analyze","prebuilt-invoice").post({contentType: "application/json",body: {// The Document Intelligence service will access the URL to the invoice image and extract data from iturlSource: invoiceUrl,},});if(isUnexpected(initialResponse)){throwinitialResponse.body.error;}constpoller=awaitgetLongRunningPoller(client,initialResponse);poller.onProgress((state)=>console.log("Operation:",state.result,state.status));constanalyzeResult=(awaitpoller.pollUntilDone()).body.analyzeResult;constdocuments=analyzeResult?.documents;constresult=documents&&documents[0];if(result){console.log(result.fields);}else{thrownewError("Expected at least one invoice in the result.");}console.log("Extracted invoice:",result.docType,`(confidence: ${result.confidence||"<undefined>"})`,);console.log("Fields:",result.fields);}main().catch((error)=>{console.error("An error occurred:",error);process.exit(1);});
DocumentIntelligence is the default export of the SDK. createClient method can also be imported which returns an object of type DocumentIntelligenceClient.
Moreover, you can name it however you want while importing a default export and it will work exactly the same.
For instance,
Harsha Nalluru (@HarshaNalluru) Hello! Thanks for your example. Using the imports the same way as you worked for me. Something weird that happens to me however is that calling poller.onProgress() or poller.pollUntilDone() fails. From my testing, getLongRunningPoller() appears to be returning the result of analyzing the document, not a poller to attempt polling the result. Have you seen that behavior before? Thanks!
@HarshaNalluru Hello! Thanks for your example. Using the imports the same way as you worked for me. Something weird that happens to me however is that calling poller.onProgress() or poller.pollUntilDone() fails. From my testing, getLongRunningPoller() appears to be returning the result of analyzing the document, not a poller to attempt polling the result. Have you seen that behavior before? Thanks!
@HarshaNalluru Hello! Thanks for your example. Using the imports the same way as you worked for me. Something weird that happens to me however is that calling poller.onProgress() or poller.pollUntilDone() fails. From my testing, getLongRunningPoller() appears to be returning the result of analyzing the document, not a poller to attempt polling the result. Have you seen that behavior before? Thanks!
Activity
HarshaNalluru commentedon Jun 3, 2024
Here is an example that works.
DocumentIntelligenceis the default export of the SDK.createClientmethod can also be imported which returns an object of typeDocumentIntelligenceClient.Moreover, you can name it however you want while importing a default export and it will work exactly the same.
For instance,
JohnnyJamesNavarro commentedon Feb 28, 2025
Harsha Nalluru (@HarshaNalluru) Hello! Thanks for your example. Using the imports the same way as you worked for me. Something weird that happens to me however is that calling
poller.onProgress()orpoller.pollUntilDone()fails. From my testing,getLongRunningPoller()appears to be returning the result of analyzing the document, not a poller to attempt polling the result. Have you seen that behavior before? Thanks!ganxiyun commentedon Mar 25, 2025
+1
frank-nankivell commentedon Jun 11, 2025
+1
faikriza commentedon Aug 17, 2025
Change the line:
const poller = await getLongRunningPoller(client, initialResponse);
to:
const poller = getLongRunningPoller(client, initialResponse);