Forum Discussion
Get data in a dataset
Hello,
I want to retrieve the contents of my dataset_ID.
Through this link https://learn.microsoft.com/fr-en/rest/api/power-bi/datasets/get-dataset-in-group, I was able to obtain the group_id and the dataset_id using the following query:
GET https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/get-dataset-in-group
Now, I would like to retrieve the contents of each dataset_ID.
How to proceed? I would need help with this.
Thank you in advance for your assistance.
Hi Christ-M ,
As you are facing a 404 error while retrieving tables please check these troubleshooting steps:1) The Service principal is still active in AAD and Access token is getting generated via the Service principle.
2) Double-check that all the variable IDs you have entered, such as tenant_id, dataset_id are accurate and correctly formatted.3) Try your API call from third party tool such as postman once to confirm everything works correctly.
Thanks and Regards
7 Replies
- freginierSolution Sage
Hey there!
Please try these steps to get your solution:
1. Use the Power BI API to Retrieve Tables in a Dataset
API Endpoint: GET https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets/{dataset_id}/tables
(This returns the list of tables in the dataset.)
2. Retrieve Table Rows (Dataset Contents)
Once you have the table names, you can fetch the rows using:
API Endpoint:GET https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets/{dataset_id}/tables/{table_name}/rows
(This returns all rows in a specific table of the dataset.)
3.
Make sure your API call includes an authorization token. You need:
Power BI API Permissions: Dataset.Read.All , Dataset.ReadWrite.All
You must authenticate using OAuth 2.0 via Azure Active Directory (AAD).How to Authenticate:
- Register an Azure AD App for Power BI.
- Get an OAuth token.
- Use the token in your API request headers: Authorization: Bearer {access_token}Hope this helps!
đđ
- Christ-MHelper I
freginier I allow to put my basic code here acr Iâm looking for a solution
import requests
# Remplacez par vos informations spĂ©cifiquesclient_id = "your_client_id"client_secret = "your_client_secret"tenant_id = "your_tenant_id"dataset_id = "your_dataset_id"workspace_id = "your_workspace_id"# Ătape 1 : Obtenir un jeton d'accĂšs via OAuth2def get_access_token():auth_headers = {"Content-Type": "application/x-www-form-urlencoded"}auth_data = {"grant_type": "client_credentials","client_id": client_id,"client_secret": client_secret,}response = requests.post(auth_url, headers=auth_headers, data=auth_data)response.raise_for_status() # GĂ©nĂšre une exception si une erreur survientreturn response.json().get("access_token")# Ătape 2 : Lister les tables du datasetdef list_tables(access_token, workspace_id, dataset_id):headers = {"Authorization": f"Bearer {access_token}"}response = requests.get(url, headers=headers)response.raise_for_status()return response.json()# Ătape 3 : ExĂ©cuter une requĂȘte DAX pour extraire les donnĂ©es d'une tabledef query_table_data(access_token, workspace_id, dataset_id, table_name):query_url = f"https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/datasets/{dataset_id}/executeQueries"query_headers = {"Authorization": f"Bearer {access_token}","Content-Type": "application/json",}query_data = {"queries": [{"query": f"EVALUATE {table_name}" # RequĂȘte DAX pour obtenir toutes les donnĂ©es de la table}]}response = requests.post(query_url, headers=query_headers, json=query_data)response.raise_for_status()return response.json()# Ătape 4 : Extraire les donnĂ©es de toutes les tablesdef extract_all_data():try:# Obtenir le token d'accĂšsaccess_token = get_access_token()print("Jeton d'accĂšs obtenu avec succĂšs.")# Lister les tablestables_info = list_tables(access_token, workspace_id, dataset_id)tables = tables_info.get("value", [])if not tables:print("Aucune table trouvĂ©e dans le dataset.")returnprint(f"Tables trouvĂ©es : {[table['name'] for table in tables]}")# Parcourir chaque table et extraire les donnĂ©esfor table in tables:table_name = table["name"]print(f"Extraction des donnĂ©es pour la table : {table_name}")data = query_table_data(access_token, workspace_id, dataset_id, table_name)if "results" in data:rows = data["results"][0]["tables"][0]["rows"]print(f"DonnĂ©es de la table {table_name} : {rows}")else:print(f"Aucune donnĂ©e trouvĂ©e pour la table {table_name}")except requests.exceptions.RequestException as e:print(f"Erreur rĂ©seau ou API : {e}")except Exception as e:print(f"Erreur : {e}")if __name__ == "__main__":extract_all_data()1. I receive an error when retrieving tables: Error 404, message: Dataset xxxxx is not Push API dataset, and it leaves me table retrieval error.
2. What solutions I can do or even how to change my code to get the tables and their content.?
3. If I want to use the Endpoint XMLA, how can I use it? What documentation should I turn to for Using XMLA ?
4. Is there a solution to my problem? how to correct the message Dataset is not Push API dataset.? - Christ-MHelper I
I allow to put my basic code here acr Iâm looking for a solution
import requests
# Remplacez par vos informations spĂ©cifiquesclient_id = "your_client_id"client_secret = "your_client_secret"tenant_id = "your_tenant_id"dataset_id = "your_dataset_id"workspace_id = "your_workspace_id"# Ătape 1 : Obtenir un jeton d'accĂšs via OAuth2def get_access_token():auth_headers = {"Content-Type": "application/x-www-form-urlencoded"}auth_data = {"grant_type": "client_credentials","client_id": client_id,"client_secret": client_secret,}response = requests.post(auth_url, headers=auth_headers, data=auth_data)response.raise_for_status() # GĂ©nĂšre une exception si une erreur survientreturn response.json().get("access_token")# Ătape 2 : Lister les tables du datasetdef list_tables(access_token, workspace_id, dataset_id):headers = {"Authorization": f"Bearer {access_token}"}response = requests.get(url, headers=headers)response.raise_for_status()return response.json()# Ătape 3 : ExĂ©cuter une requĂȘte DAX pour extraire les donnĂ©es d'une tabledef query_table_data(access_token, workspace_id, dataset_id, table_name):query_url = f"https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/datasets/{dataset_id}/executeQueries"query_headers = {"Authorization": f"Bearer {access_token}","Content-Type": "application/json",}query_data = {"queries": [{"query": f"EVALUATE {table_name}" # RequĂȘte DAX pour obtenir toutes les donnĂ©es de la table}]}response = requests.post(query_url, headers=query_headers, json=query_data)response.raise_for_status()return response.json()# Ătape 4 : Extraire les donnĂ©es de toutes les tablesdef extract_all_data():try:# Obtenir le token d'accĂšsaccess_token = get_access_token()print("Jeton d'accĂšs obtenu avec succĂšs.")# Lister les tablestables_info = list_tables(access_token, workspace_id, dataset_id)tables = tables_info.get("value", [])if not tables:print("Aucune table trouvĂ©e dans le dataset.")returnprint(f"Tables trouvĂ©es : {[table['name'] for table in tables]}")# Parcourir chaque table et extraire les donnĂ©esfor table in tables:table_name = table["name"]print(f"Extraction des donnĂ©es pour la table : {table_name}")data = query_table_data(access_token, workspace_id, dataset_id, table_name)if "results" in data:rows = data["results"][0]["tables"][0]["rows"]print(f"DonnĂ©es de la table {table_name} : {rows}")else:print(f"Aucune donnĂ©e trouvĂ©e pour la table {table_name}")except requests.exceptions.RequestException as e:print(f"Erreur rĂ©seau ou API : {e}")except Exception as e:print(f"Erreur : {e}")if __name__ == "__main__":extract_all_data()1. I receive an error when retrieving tables: Error 404, message: Dataset xxxxx is not Push API dataset, and it leaves me table retrieval error.
2. What solutions I can do or even how to change my code to get the tables and their content.?
3. If I want to use the Endpoint XMLA, how can I use it? What documentation should I turn to for Using XMLA ?
4. Is there a solution to my problem? how to correct the message Dataset is not Push API dataset.?- v-nmadadi-msftCommunity Support
Hi Christ-M ,
As you are facing a 404 error while retrieving tables please check these troubleshooting steps:1) The Service principal is still active in AAD and Access token is getting generated via the Service principle.
2) Double-check that all the variable IDs you have entered, such as tenant_id, dataset_id are accurate and correctly formatted.3) Try your API call from third party tool such as postman once to confirm everything works correctly.
Thanks and Regards
- freginierSolution Sage
Hello,
I am really not sure then.
Sorry I couldn't help more đ
- v-nmadadi-msftCommunity Support
Hi Christ-M ,
We are following up once again regarding your query. Could you please confirm if the issue has been resolved?If the issue has been resolved, we kindly request you to share the resolution or key insights here to help others in the community. If we donât hear back, weâll go ahead and close this thread.
Should you need further assistance in the future, we encourage you to reach out via the Microsoft Fabric Community Forum and create a new thread or reopen this thread. Weâll be happy to help.
Thank you for your understanding and participation.