Fabric is a very powerful tool and a great place to store your data. In some cases, we want to be able to make subsets of this data available to external tools via API calls. To accomplish this requirement, we can do the following.

Register a Microsoft Entra App in the Azure portal. Here is a link to accomplish this if you need guidance: Create a Microsoft Entra ID app – Microsoft Fabric REST APIs | Microsoft Learn

When setting up our application, it is important to get a few configurations set up.

Authentication > Add a platform > Mobile and desktop application. This will automatically generate redirect URIs to use, choose the first option.

https://login.microsoftonline.com/common/oauth2/nativeclient

Make sure Allow public client flows is set to Yes.

Under the Manage list, select API permissions, then Add permission.

Add the PowerBI Service, select Delegated permissions, and select GraphQLApi.Execute.All and Item.Execute.All permissions.

After we have our Entra ID set up, we need to grant permissions to the API and any data sets that our API would call. The additional permissions are commonly granted at the user level so first we need to go to the Tenant Admin portal in Fabric to allow permissions to be granted to our Entra Id.

In Fabric >  Tenant Admin portal > Tenant Settings > Developer settings. Enable Service Principals can use Fabric APIs.

Then go to the API and all relevant data sources and select Manage permissions > Add user.

Now we can add the name of our Entra app here and ensure they are enabled to Run Queries and Mutations.

Now we are able to run API calls to query our data, but we are un able to call Stored Procedures. To do this we need to additionally grant our Entra Id Contributor permissions.

With all the configuration done, now we can start getting our data!

First we can get a token like so.

URL is https://login.microsoftonline.com/TENTANTID/oauth2/v2.0/token

Client Id and Client secret are values from our Entra Id

Ensure the scope is set to https://api.fabric.microsoft.com/.default


Using the access_token from the previous call, we can make query calls like so:

Here is an example using the sample data set from Fabric for holidays. You can use Fabric to generate code and the URL if needed which can be helpful.

I will avoid getting into query specifics here but it is work calling out that you can pass in variables, test with the ‘GraphQL’ node for the request body in Postman, and add various filters/etc. in the GraphQL query. A quick example of a filtered query could be as follows:

query { customers (first: 10, filter:  {
       orderingcustomeraccountnumber:  {
          eq: "123"
       }
    }) {
       items {
          salesordernumber,
          orderingcustomeraccountnumber
       }
    }
  }

Final example: calling a stored procedure and seeing the GraphQL body format in Postman.

For reference, if you do not add the Entra Id as a contributor and you try to run a stored procedure, or if you do not enable to Entra Id on the stored procedure, you will get the following error:

{
  "errors": [
    {
      "message": "An internal execution error occured",
      "locations": [
        {
          "line": 2,
          "column": 5
        }
      ],
      "path": [
        "executeGetHolidayName"
      ],
      "extensions": {
        "code": "InternalServerError"
      }
    }
  ]
}

I hope this helped you get connected to data in Fabric and you are now able to successfully make GraphQL API calls to utilize your data externally as needed!

Microsoft documentation for reference: Connect applications to Fabric API for GraphQL – Microsoft Fabric | Microsoft Learn

Keep reading about D365 tips and tricks here:  https://markedcode.com/index.php/category/d365/

For technical questions, please visit https://d365techsupport.com

Author

Write A Comment