Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply

Calling Azure ML Web Service from Power BI

I have looked at other posts covering this topic, but none seem to explain, in a way I can comprehend, how to do what I want to acheive.  I am pulling in Twitter data via API directly into Power BI.  I have been using a custom function to call the Microsoft Cognitive Services Sentiment Analysis API to score the Tweets.  However, I have an Azure ML Web Service for text analytics that I want to use instead of Microsoft's Cognitive Services.

 

I know how to see the request URL and API key for a published web service in Azure ML.  I also know where to find the R code example.  I am not sure how to implement a call to this API directly in Power BI (either via API or R), but also, could it be possible to do the scoring with R directly in an R script in the query editor?

4 REPLIES 4
Eric_Zhang
Employee
Employee

@dkay84_PowerBI

 

What is your web service like? Currently Power BI doesn't support fetching data from Azure ML, you might choose "get data->web" or call an api from Power Query.

My code to call the Cognitive Services API looks as follows:

(Source as table) as any =>
let
    JsonRecords = Text.FromBinary(Json.FromValue(Source)),
    JsonRequest = "{""documents"": " & JsonRecords & "}",

    JsonContent = Text.ToBinary(JsonRequest, TextEncoding.Ascii),
    Response =
        Web.Contents("https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment?",
            [
                Headers = [#"Ocp-Apim-Subscription-Key"= "MY KEY",
                           #"Content-Type"="application/json", Accept="application/json"],
                Content=JsonContent 
            ]),
    JsonResponse = Json.Document(Response,1252)
in
    JsonResponse

Since the Azure ML web service gives a url and key, I figured it would be possible to call it similar to the call above.  However, the structure of the call and the required headers is a bit different, and trying to figure out the required pieces from the Azure ML web service API page is difficult.

 

Any thoughts?


@dkay84_PowerBI wrote:

My code to call the Cognitive Services API looks as follows:

(Source as table) as any =>
let
    JsonRecords = Text.FromBinary(Json.FromValue(Source)),
    JsonRequest = "{""documents"": " & JsonRecords & "}",

    JsonContent = Text.ToBinary(JsonRequest, TextEncoding.Ascii),
    Response =
        Web.Contents("https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment?",
            [
                Headers = [#"Ocp-Apim-Subscription-Key"= "MY KEY",
                           #"Content-Type"="application/json", Accept="application/json"],
                Content=JsonContent 
            ]),
    JsonResponse = Json.Document(Response,1252)
in
    JsonResponse

Since the Azure ML web service gives a url and key, I figured it would be possible to call it similar to the call above.  However, the structure of the call and the required headers is a bit different, and trying to figure out the required pieces from the Azure ML web service API page is difficult.

 

Any thoughts?


 

As far as I know, http request is not language-specific, so either Power Query or any other language can send a request with proper request header. In your case, as you don't know how to apply the url and key, which is actually Azure ML specific, then I suggest you firstly ask a question like "how to call the Azure ML web service API" in the dedicated Azure ML forum, then transplant the answer to Power Query.

@dkay84_PowerBI - this code works only in desktop right? not in powerbi.com 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.