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

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

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
Contributor III

Hi @Anonymous,

 

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
govindarajan_d
Contributor III

Hi @Anonymous,

 

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/'

 

v-prasare
Honored Contributor II

Hi @Anonymous,

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
Honored Contributor II

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
Honored Contributor II

Hi @Anonymous, 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"

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Free Fabric Certifications

Free Fabric Certifications

Get Fabric certified for free! Don't miss your chance.

January Fabric Update Carousel

Fabric Monthly Update - January 2026

Check out the January 2026 Fabric update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Users online (2,727)