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

Join us at FabCon Vienna from September 15-18, 2025, for the ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM. Get registered

Reply
Sanket9831
New Member

Workload Development Toolkit CRUD APIs

Hi there,

I am trying to generate Authentication bearer token on the fly, to create Datawarehouse via sample workload using the POST APIs available for it. How to: Create warehouses with case-insensitive (CI) collation - Microsoft Fabric | Microsoft Learn

Just FYI: I was able to do so  by hard coding my bearer token.

Workload doc for the CRUD APIs auth setup is Authentication setup - Microsoft Fabric | Microsoft Learn

Please help me with some alternative.

 

 

import { PublicClientApplication, AuthenticationResult } from "@azure/msal-browser";

/// MSAL configuration
const msalConfig = {
auth: {
clientId: "************************", // Replace with your client ID
authority: "https://login.microsoftonline.com/***************", // Replace with your tenant ID
redirectUri: "http://localhost:60006/close", // Replace with your redirect URI
},
};

const msalInstance = new PublicClientApplication(msalConfig);

async function initializeMsal() {
await msalInstance.initialize();
}

async function acquireToken(): Promise<string> {
const request = {
scopes: ["https:api://localdevinstance/******************************/Org.WorkloadSample/FabricWorkloadControl"], // Replace with your API scopes
};

try {
const response: AuthenticationResult = await msalInstance.acquireTokenSilent(request);
return response.accessToken;
} catch (error) {
const response: AuthenticationResult = await msalInstance.acquireTokenPopup(request);
return response.accessToken;
}
}

 

 

 

1 ACCEPTED SOLUTION
govindarajan_d
Super User
Super User

Hi @Sanket9831,

 

You could try python in Fabric notebook. This way you don't have to worry about setting up access token retrieval since you can directly get it from Fabric. The following code will allow you to call any REST API in Fabric. 

 

#Helper function to call Fabric REST API

from notebookutils import mssparkutils as msu
import requests
import time

def call_fabric_api(method, uri, payload=None):
    endpoint = "https://api.fabric.microsoft.com/v1"

    # Get PBI Access token and have it in the header for Authorization
    headers = {
        "Authorization": "Bearer " + msu.credentials.getToken("pbi"),
        "Content-Type": "application/json"
    }

    #Create new session and try sending a request to the Fabric REST API
    session = requests.Session()
    try:
        url = f"{endpoint}/{uri}"
            
        response = session.request(method, url, headers=headers, json=payload, timeout=120)
        print(response.json())
        return response.json()

    except requests.RequestException as ex:
        print(ex)

 

But if you are looking for access token specifically, the following is the CURL format that I normally use with Postman

curl --location 'https://login.microsoftonline.com/<Tenant ID>/oauth2/token?Content-Type=application%2Fx-www-form-urlencoded' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=<Service Principal ID or Username>' \
--data-urlencode 'client_secret=<Secret or Password>' \
--data-urlencode 'resource=https://management.azure.com/'

 

View solution in original post

4 REPLIES 4
v-prasare
Community Support
Community Support

Hi @Sanket9831, Hope your doing well.

 

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution we have provided for your issue worked? or let us know if you need any further assistance here?

 

 

Your feedback is important to us, Looking forward to your response. 

 

Thanks,

Prashanth Are

MS Fabric community support.

 

Did we answer your question? Mark post as a solution, this will help others!

If our response(s) assisted you in any way, don't forget to drop me a "Kudos"

v-prasare
Community Support
Community Support

Hi @Sanket9831,

Hope your doing well.

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution we have provided for your issue worked? or let us know if you need any further assistance here?

 

 

Your feedback is important to us, Looking forward to your response. 

 

Thanks,

Prashanth Are

MS Fabric community support.

v-prasare
Community Support
Community Support

Hi @Sanket9831,

Hope your doing well.

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution we have provided for your issue worked? or let us know if you need any further assistance here?

 

 

Your feedback is important to us, Looking forward to your response. 

 

Thanks,

Prashanth Are

MS Fabric community support.

 

govindarajan_d
Super User
Super User

Hi @Sanket9831,

 

You could try python in Fabric notebook. This way you don't have to worry about setting up access token retrieval since you can directly get it from Fabric. The following code will allow you to call any REST API in Fabric. 

 

#Helper function to call Fabric REST API

from notebookutils import mssparkutils as msu
import requests
import time

def call_fabric_api(method, uri, payload=None):
    endpoint = "https://api.fabric.microsoft.com/v1"

    # Get PBI Access token and have it in the header for Authorization
    headers = {
        "Authorization": "Bearer " + msu.credentials.getToken("pbi"),
        "Content-Type": "application/json"
    }

    #Create new session and try sending a request to the Fabric REST API
    session = requests.Session()
    try:
        url = f"{endpoint}/{uri}"
            
        response = session.request(method, url, headers=headers, json=payload, timeout=120)
        print(response.json())
        return response.json()

    except requests.RequestException as ex:
        print(ex)

 

But if you are looking for access token specifically, the following is the CURL format that I normally use with Postman

curl --location 'https://login.microsoftonline.com/<Tenant ID>/oauth2/token?Content-Type=application%2Fx-www-form-urlencoded' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=<Service Principal ID or Username>' \
--data-urlencode 'client_secret=<Secret or Password>' \
--data-urlencode 'resource=https://management.azure.com/'

 

Helpful resources

Announcements
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 FBC25 Carousel

Fabric Monthly Update - June 2025

Check out the June 2025 Fabric update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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