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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Laxmikanth
Frequent Visitor

Issue with table names having spaces

Hi There, 

 

The below code works totally fine when the table name is single word. If the table name has any spaces it is throwing error.

 

import json
import requests

# Replace with your Power BI tenant ID and client ID and client secret
tenant_id = ''
client_id = ''
client_secret = ''
# Workspace ID
workspace_id = ''
# Dataset ID
dataset_id = ''


# OAuth2 endpoint for token acquisition
token_url = f'https://login.microsoftonline.com/{tenant_id}/oauth2/token'
# Request body for token acquisition
token_data = {
'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret,
'resource': 'https://analysis.windows.net/powerbi/api'
}

# Request token from Azure
token_response = requests.get(token_url, data=token_data)
token_response_data = token_response.json()

# Check for token acquisition errors
if token_response.status_code != 200:
print({'statusCode': 500,
'body': json.dumps({'error': token_response_data.get('error', 'Failed to acquire token')})})

# Get access token
access_token = token_response_data['access_token']


api_url = f'https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/datasets/{dataset_id}/executeQueries'

# HTTP headers with authorization
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}

payload = {
"queries": [
{
"query": "Evaluate 'Users'"
}
],
"serializerSettings": {
"includeNulls": False
},
"impersonatedUserName": "<your_user>@<your_domain>.com"
}

response = requests.post(api_url, headers=headers, json=payload)
print(response.text)

 

Pass Scenario: "query": "Evaluate 'Users'"

Fail Scenario: "query": "Evaluate 'Report views'"

 

Laxmikanth_0-1714489278333.png

 

Please let me know how we can pass the table names which has spaces.

 

Thanks,

Laxmikanth

3 REPLIES 3
lbendlin
Super User
Super User

Hi There,

 

Thanks for the update.

 

The 2nd method in the article mentions to enclose single quotes in double quotes and it has been done. It worked for the one worded table but doesn't work for the table names which have spaces.

 

Pass Scenario: "query": "Evaluate 'Users'"

Fail Scenario: "query": "Evaluate 'Report views'"

 

Thanks,

Laxmikanth

Shouldn't it be 

 

"query": "Evaluate "'"Report views"'""

 

?

 

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.