1. Larry Pettit
  2. PowerBuilder
  3. Friday, 12 July 2024 12:26 PM UTC

I generally don't like to display my ignorance, but I'm going to bite the bullet and ask a stupid question.

Following is sample C# code off of Microsoft's website.  If I wanted to make this call from PowerBuilder 2022 R3 instead of C#:

  1. Is it possible?
  2. Would it be a REST call?  External Function? Something else?
  3. Would I need to write a C# object for PowerBuilder to call?

If somebody had some free time and didn't know what to do, could you please point me in the right direction?  It would be very much appreciated.  I can just write the whole app in C# but I'd like to know what my options are and what PowerBuilder is capable of.

C# Code:

using Azure;
using Azure.AI.DocumentIntelligence;

string endpoint = "<endpoint>";
string key = "<access-key>";
AzureKeyCredential cred = new AzureKeyCredential(key);
DocumentIntelligenceClient client = new DocumentIntelligenceClient (new Uri(endpoint), cred);

Uri fileUri = new Uri ("<url-of-document-to-analyze>");

AnalyzeDocumentOperation operation = await client.AnalyzeDocumentFromUriAsync(WaitUntil.Completed, "prebuilt-layout", fileUri);

AnalyzeResult result = operation.Value;

 

THANK YOU!!!!

Accepted Answer
mike S Accepted Answer Pending Moderation
  1. Friday, 12 July 2024 13:36 PM UTC
  2. PowerBuilder
  3. # Permalink

look at the REST API reference for the service you are accessing.  Azure is good at documenting all the services with the full rest api. 

Document Models - Analyze Document - REST API (Azure Azure AI Services) | Microsoft Learn

 

out of curiosity, are you planning on doing OCR with it, or something else?

Comment
  1. Nasir Ahmad
  2. Monday, 15 July 2024 21:44 PM UTC
Asked AI and it gave me this code.. I think its a good point to start



// Declare variables

RESTClient lrest_Client

String ls_URL, ls_RequestBody, ls_ResponseText

Integer li_StatusCode, li_RC



// Create RESTClient object

lrest_Client = Create RESTClient



// Set the API URL

ls_URL = "https://YOUR-RESOURCE-NAME.cognitiveservices.azure.com/formrecognizer/documentModels/prebuilt-document:analyze?api-version=2024-02-29-preview"



// Set headers

lrest_Client.SetRequestHeader("Content-Type", "application/json")

lrest_Client.SetRequestHeader("Ocp-Apim-Subscription-Key", "YOUR_SUBSCRIPTION_KEY")

//lrest_Client.setcredentials( /*boolean isproxyauth*/, /*integer scheme*/, /*string user*/, /*string password */)



// Prepare the request body

ls_RequestBody = '{"urlSource": "YOUR_DOCUMENT_URL"}'



// Make the POST request

//li_RC = lrest_Client.SendRequest("POST", ls_URL, ls_RequestBody)

String ls_Response

li_RC = lrest_Client.SendPostrequest( ls_URL, ls_RequestBody, ls_ResponseText)



// Check if the request was successful

if li_RC = 1 then

// Get the response status code

li_StatusCode = lrest_Client.GetResponseStatusCode()



// Get the response text

// ls_ResponseText = lrest_Client.GetResponseBody()



// Check the status code

if li_StatusCode = 202 then

// Request accepted, get the operation-location header

String ls_OperationLocation = lrest_Client.GetResponseHeader("Operation-Location")

MessageBox("Success", "Document analysis started. Operation URL: " + ls_OperationLocation)

else

// Request failed

MessageBox("Error", "Failed to start document analysis. Status code: " + String(li_StatusCode))

end if

else

// Request failed to send

MessageBox("Error", "Failed to send request to the API.")

end if



// Destroy the RESTClient object

Destroy lrest_Client
  1. Helpful 1
There are no comments made yet.
Francisco Martinez @Appeon Accepted Answer Pending Moderation
  1. Friday, 12 July 2024 14:57 PM UTC
  2. PowerBuilder
  3. # 1

Hi Larry,

As an alternative, you can also make calls to C# code from PowerBuilder, provided your version of PB is new enough. Please see here: https://docs.appeon.com/pb2022/application_techniques/ch05s01s01.html

This way you can directly use the Azure C# libraries instead of having to do the REST calls yourself.

Most likely you will have to create a wrapper class, because there are some limitations to what C# code can be invoked from PB.

Regards,
Francisco

Comment
There are no comments made yet.
Larry Pettit Accepted Answer Pending Moderation
  1. Friday, 12 July 2024 14:51 PM UTC
  2. PowerBuilder
  3. # 2

Thanks for the REST reference.

We are fully integrating Microsoft AI Document Processing into Carillon ERP.  For example, vendor invoices will be analyzed and the Voucher Entry windows will be automatically populated with the information in the document.  Many different applications in Payroll, Receivables, etc.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.