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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
anshul_imriel
Regular Visitor

Need to fetch bearer token that is displayed on 'try it' feature on microsoft's documentation page

I am working on a project in which I need to delete rows in the streaming dataset of the PowerBI service. I tried to generate a bearer token for Powerbi using the Azure app service but it did not work for sending a delete request. Another way I found was using a PowerShell module named 'MicrosoftPowerBIMgmt' from which I can connect to my powerbi account using 'Connect-PowerBIServiceAccount' and run delete command with `Invoke-PowerBIRestMethod -Method DELETE -Url https://api.powerbi.com/v1.0/myorg/datasets/{datasetId}//tables/{tableName}/rows'`, but with this method I need to login to my account manually when running in WSL. Later I found out that on Microsoft's documentation page for Push Datasets - Datasets DeleteRows, I can use the 'Try it' feature that will run some network calls in the backend and generate a bearer token under the 'Request Preview' section with which I can run DELETE request.

anshul_imriel_0-1717487843456.png

I tested this token in Postman and Python requests, and both work fine.

Now my question is how can I generate this token in Python using the requests library so that I can send a DELETE request for powerBI to delete rows in the streaming dataset?

1 REPLY 1
Anonymous
Not applicable

Hi @anshul_imriel ,

You may try your Azure app service again, you can follow the steps below to resolve the issue:

1.Ensure that the Azure AD application has the required permissions to interact with the Power BI API.

2. Generate a holder token using the following Python script:

import requests

# Replace these with your tenant ID, client ID, and client secret
tenant_id = 'TENANT_ID'
client_id = 'CLIENT_ID'
client_secret = 'CLIENT_SECRET'

# Construct the URL for token generation
url = f'https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token'

# Define the payload for the token request
payload = {
    'grant_type': 'client_credentials',
    'client_id': client_id,
    'client_secret': client_secret,
    'scope': 'https://graph.microsoft.com/.default'
}

# Make the POST request to obtain the token
response = requests.post(url, data=payload)

# Extract the access token from the response
access_token = response.json().get('access_token')

print(access_token)

3. The following is an example of how to send a DELETE request using the holder token:

import requests

# Replace with your dataset ID and table name
dataset_id = 'DATASET_ID'
table_name = 'TABLE_NAME'

# The API endpoint for deleting rows
url = f'https://api.powerbi.com/v1.0/myorg/datasets/{dataset_id}/tables/{table_name}/rows'

# The headers including the authorization token
headers = {
    'Authorization': f'Bearer {access_token}'
}

# Send the DELETE request
response = requests.delete(url, headers=headers)

print(response.status_code)

Best Regards,

Ada Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors