Connect PowerBI to GraphQL endpoint

Connect PowerBI to GraphQL endpoint

In this article, we will be using a GraphQL endpoint, created through MuleSoft Anypoint DataGraph, to connect PowerBI using its Power Query. As PowerBI does not provide an Out-of-the-Box configurable REST API adaptor, Power Query is a great possibility to use M language. To learn more about Power Queries, click here.

Pre-requisites

The scenario for this article contains 4 REST APIs (connected to Salesforce) which are unified into a DataGraph scheme and accessible via a single GraphQL endpoint.

Es wurde kein Alt-Text für dieses Bild angegeben.


Step 1: Get Anypoint DataGraph endpoint details

As a first step, we need to have the Anypoint DataGraph endpoint information. This includes the endpoint itself, as well as the client-id and client-secret. You can find this information in the "Run Query" wizard by clicking on Copy & Share Query endpoint:

Es wurde kein Alt-Text für dieses Bild angegeben.

It will open the endpoint dialog with all required information.

Es wurde kein Alt-Text für dieses Bild angegeben.

Step 2: Open PowerBI and create a Power Query

In PowerBI, click on Get Data from the Home Menu and select More.

Es wurde kein Alt-Text für dieses Bild angegeben.

In the search box, enter "Blank Query", select the Blank Query on the right side in the list and click Connect.

Es wurde kein Alt-Text für dieses Bild angegeben.

In the Power Query Editor, open the Advanced Editor from the Home Menu.

Es wurde kein Alt-Text für dieses Bild angegeben.

Step 3: Write the M script to connect to GraphQL endpoint

In the Advanced Editor, we will be using the data functions of Power BI to connect to web content. All functions are listed here. As we are connecting to GraphQL endpoint, we need to use the data function Web.Contents.

Web.Contents(url as text, optional options as nullable record) as binary        

You can find Web.Contents generic examples here.

We need to connect to the GraphQL endpoint using client-id and client-secret. Our script will differ slightly from the generic examples.

let
	url = "https://datagraph-xxx.xxx.xxx-xxx.us-e2.cloudhub.io/graphql",
	client_id = "xxxxxxxxxxxxxxxx",
	client_secret = "xxxxxxxxxxxxxxxxx",

    Source = Web.Contents(
	url,
	[
		Headers=[
			#"Method"="POST",
			#"Content-Type"="application/json",
			#"client_id"=client_id,
            #"client_secret"=client_secret
		],
		Content=Text.ToBinary("{""query"": ""{ campaigns{ id name type startDate endDate status expRevenue } accounts{ id name type openOpps openOppsValue annualRevenue } opportunities{ id name type probability amount createdDate closeDate stage leadSource accountName } leads{ id name company annualRevenua leadSource country leadPriority leadStatus totalScore leadQuality }}""}")
	]
    ),

    #"JSON" = Json.Document(Source)
in
    JSON        

After entering the code, click on Done.

Es wurde kein Alt-Text für dieses Bild angegeben.

You will be prompted to provide credentials to connect to the endpoint. Select Credential Type Anonymous.

Es wurde kein Alt-Text für dieses Bild angegeben.

Now you should see the data Entry with single Record in the query section.

Es wurde kein Alt-Text für dieses Bild angegeben.

Step 4: Format and Extract the Data

As the whole query has been returned in a nested and raw format, you need to extract and format the data to your needs - make use of the PowerBI data extraction capabilities.

Es wurde kein Alt-Text für dieses Bild angegeben.

Finally, click on Close & Apply and you are ready to build your graphs.

Es wurde kein Alt-Text für dieses Bild angegeben.

Step 5: Create Reports

Once your query is ready, you can create PowerBI reports from the GraphQL endpoint.

Es wurde kein Alt-Text für dieses Bild angegeben.

That's it! You have successfully connected PowerBI with GraphQL via MuleSoft Anypoint DataGraph.

Happy connecting ?? ?? ???!!!

Try it out yourself

With no prior experience in PowerBI I was trying to integrate it with a GraphQL endpoint for a POC, found this post luckily and saved myself a couple of hours. Thank you for taking time posting this.

回复
KIJO MISHAK

Assistant Estimation Engineer

1 年

I have done all as per this article but not able to connect power bi to GrapQL, I receive an error for (400): Bad Request. I am using same M script which provide in this article, Can you please tell me why?

回复

Will it work for hasura Graphql??

回复
Sudhir K.

CTO | Practice Leader | Dreamforce Speaker | Salesforce Trailblazer | GTM Champion | MuleSoft Ambassador Alumni | DNI | Customer Success Senior Manager at Salesforce

2 年

Best content creator Amir Khan ????????????

要查看或添加评论,请登录

Amir Khan的更多文章

  • MuleSoft AI Chain is a Product now

    MuleSoft AI Chain is a Product now

    ?? ??????????????, ???????????????? ???? ?????????? ?????? ???????? ???????????????????? ??????????????????!?? ??…

    48 条评论
  • LocalStack and MuleSoft

    LocalStack and MuleSoft

    I recently discovered LocalStack, a fully functional AWS services emulation for local development and testing. First I…

    3 条评论
  • How API-led Connectivity serves Business Intelligence and Analytics

    How API-led Connectivity serves Business Intelligence and Analytics

    BI tools are playing a major role in making data professionals understand huge quantities of data that enterprises…

    14 条评论
  • Enable Business Intelligence & Analytics with MuleSoft DataGraph

    Enable Business Intelligence & Analytics with MuleSoft DataGraph

    Through acquisitions, it has become a new norm for enterprises to manage multiple systems of records of the acquired…

  • Integrate Grafana with Anypoint DataGraph

    Integrate Grafana with Anypoint DataGraph

    DataGraph is just AWESOME. Think about the old days and the flat-file-based data sources.

    3 条评论
  • Unleash the power of your data with Anypoint DataGraph

    Unleash the power of your data with Anypoint DataGraph

    On May 18, 2021, MuleSoft released its powerful new Anypoint DataGraph. Developers can easily access data from multiple…

    1 条评论
  • Why MuleSoft?

    Why MuleSoft?

    In the last 14 years, I have been working for some amazing companies with a focus on Application Lifecycle Management…

    79 条评论
  • Join the ALM Octane Academy

    Join the ALM Octane Academy

    We have launched a YouTube channel named “Octane Academy” with the purpose to enable you to use ALM Octane. This is a…

  • Integrate JMeter with ALM Octane

    Integrate JMeter with ALM Octane

    Recently I have been on different engagements, where JMeter Load/Performance Testing were part of a continuous…

  • Generating Awesome Graphs for ALM Octane using REST API with Dash & Plotly

    Generating Awesome Graphs for ALM Octane using REST API with Dash & Plotly

    In my last article, I provided some examples on how to access the ALM Octane REST API using Python. Before continuing…

    3 条评论

社区洞察

其他会员也浏览了