Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
Hello Everybody,
I have a problem with a Power BI API
First i get the Token:
$url = 'https://login.windows.net/' . $directoryIdAzure . '/oauth2/token'
/** @var GuzzleHttp\Client $client **/
$response = $client->post(
$url,
[
"headers" => [
"Accept" => "application/json"
],
'form_params' => [
'resource' => 'https://analysis.windows.net/powerbi/api',
'client_id' => $clientIdAzure,
'client_secret' => $clientSecretAzure,
'grant_type' => 'client_credentials',
'username' => $user,
'password' => $pass,
'scope' => 'openid',
]
]
);
$body = json_decode($response->getBody()->getContents(), true);
$token = $body['access_token'];
After i need list all Workspaces using a token
$client2 = new \GuzzleHttp\Client();
$res = $client2->request(
'GET',
'https://api.powerbi.com/v1.0/myorg/groups',
[
'headers' =>
[
'Authorization' => 'Bearer ' . $token,
'Accept' => 'application/json',
'Content-type' => 'application/json'
]
]
);
$workspaces = json_decode($res->getBody()->getContents(), true);
Return this error for me:
"Client error: `GET https://api.powerbi.com/v1.0/myorg/groups` resulted in a `401 Unauthorized` response"
The permissions in the Azure it's OK:
Solved! Go to Solution.
I Solved my problem.
I change
'grant_type' => 'client_credentials',
to
'grant_type' => 'password',
and I had to disable Security Defaults in the Azure
Azure Portal > Azure AD > Properties > Click on Manage Security Defaults link > Toggle Enable Security Defaults button to NO.
I hope thats help anyone.
You also need to enable use of the Fabric API within the Developer settings of your Power BI tenant. See ths link for details: https://learn.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal
I Solved my problem.
I change
'grant_type' => 'client_credentials',
to
'grant_type' => 'password',
and I had to disable Security Defaults in the Azure
Azure Portal > Azure AD > Properties > Click on Manage Security Defaults link > Toggle Enable Security Defaults button to NO.
I hope thats help anyone.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
Check out the February 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 |
| User | Count |
|---|---|
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |