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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
dkay84_PowerBI
Microsoft Employee
Microsoft Employee

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
Microsoft Employee
Microsoft 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
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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