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#:
- Is it possible?
- Would it be a REST call? External Function? Something else?
- 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!!!!
// 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