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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

Rest API executeQueries Python

Hello Developer Community,

Context:
Programming Language- Python
Enviroment -Azure Databricks
Authentication Type: 'acquire_token_with_client_credentials'

Problem Statement:
While using the 'executeQueries' rest api call, i receive a '400 Client Error: Bad Request for url'. My code is as follows:

 

 

 

post_query = 'https://api.powerbi.com/v1.0/myorg/datasets/<dataset-id>/executeQueries'
header = {'Authorization': f'Bearer {access_token}','Content-Type' : 'application/json'}
body = {
  "queries": [
    {
      "query": "EVALUATE VALUES(Merge1[Email])"
}
  ],
  "serializerSettings": {
    "includeNulls": "true"
  }
}

post_r = requests.post(url=post_query,data=body, headers=header)
post_r.raise_for_status()

 

 

 


Additional Context:
Alterantive Trial-1: I've tried using  the following, but was not sucessful.

 

 

 

post_r = requests.post(url=post_query,json= json.dumps(body), headers=header)

 

 

 

Alternative Trial-2: I tried the same dataset and body using the Microsoft documentation 'Try it' option(https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/execute-queries#code-try-0) and was succesful in receving the following:
Rest_api_error.png.jpg

 

I would really appreciate any response which would help me get closer to the solution.
Thanks in advance.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thank you for the reply. But i think i solved the issue by passing the body as a string value.

body = '''{
  "queries": [
    {
      "query": "EVALUATE VALUES(Merge1[Email])"
}
  ],
  "serializerSettings": {
    "includeNulls": "true"
  }
}'''


 

View solution in original post

3 REPLIES 3
mshilendhari
Frequent Visitor

Hi, I had similar issue and your solution fixed the 400 error.

 

But now i am getting 401 error below:

<Response [401]> {"error":{"code":"PowerBINotAuthorizedException","pbi.error":{"code":"PowerBINotAuthorizedException","parameters":{},"details":[],"exceptionCulprit":1}}} JSON Response {'error': {'code': 'PowerBINotAuthorizedException', 'pbi.error': {'code': 'PowerBINotAuthorizedException', 'parameters': {}, 'details': [], 'exceptionCulprit': 1}}}

 

Here's my code:

 

body = '''{
"queries": [
{
"query": "EVALUATE VALUES(BENEFIT_PLAN[LAST_UPDATE_DATE])"
}
]
}'''
api_call = requests.post(url=datasets_rowcount_url,data=body, headers=header)
query_json=api_call.text.encode().decode('utf-8-sig')
print(query_json)

V-lianl-msft
Community Support
Community Support

HTTPError: 400 Client Error: Bad Request means the request you made has error. And I think the server may check some headers in the HTTP reques.

You could refer to this thread:

https://community.powerbi.com/t5/Developer/Get-Reports-REST-api-not-working-Showing-400-Bad-Request/... 

Anonymous
Not applicable

Thank you for the reply. But i think i solved the issue by passing the body as a string value.

body = '''{
  "queries": [
    {
      "query": "EVALUATE VALUES(Merge1[Email])"
}
  ],
  "serializerSettings": {
    "includeNulls": "true"
  }
}'''


 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.