79379371

Date: 2025-01-22 22:33:18
Score: 0.5
Natty:
Report link

How I should be able to use Microsoft Power BI API for delete workspaces? When I created a workspaces linked to service entity profile I did so:

public function createWorkspace($accessToken, $profileId, $workspaceName)
{
    $response = Http::withHeaders([
        'Authorization' => 'Bearer ' . $accessToken,
        'X-PowerBI-Profile-Id' => $profileId,
        'Content-Type' => 'application/json',
    ])->post($this->baseUrl . 'groups', [
        'name' => $workspaceName,
    ]);

    if ($response->successful()) {
        return $response->json();
    }

    throw new \Exception('Error creating workspace: ' . $response->body());
}     

Then I grant access permissions like this:

public function grantAccessPermissions($accessToken, $workspaceId, $profileId)
{
    $response = Http::withHeaders([
        'Authorization' => 'Bearer ' . $accessToken,
        'Content-Type' => 'application/json',
        'X-PowerBI-Profile-Id' => $profileId,
    ])->post($this->baseUrl . 'groups/' . $workspaceId . '/users', [
        'groupUserAccessRight' => 'Admin',
        'identifier' => '487eabe2-22ea-4419-b8f9-e7f09fa0b875',
        'principalType' => 'User',
        'emailAddress' => '###@####.onmicrosoft.com'
    ]);

    if ($response->successful()) {
        Log::info('Respuesta de grantAccessPermissions: ' . json_encode($response->json()));
        return $response->json();
    }

    throw new \Exception('Error granting access permissions: ' . $response->body());
}  

Right here I send the 'emailAddress' parameter in request body which is 'Admin' of premium capacity assigned to service principal. And the workspace is showing in Power BI Service correctly.

But I can't delete the workspace created.

public function deleteWorkspace($accessToken, $workspaceId)
{
    if (empty($workspaceId)) {
        throw new \Exception('El Workspace ID no puede estar vacĂ­o.');
    }
    Log::info('Workspace ID que llega a deleteWorkspace: ' . $workspaceId);
    $response = Http::withHeaders([
        'Authorization' => 'Bearer ' . $accessToken,
        'Content-Type' => 'application/json',
    ])->delete($this->baseUrl . 'groups/' . $workspaceId);

    if ($response->successful()) {
        return $response->json();
    }

    throw new \Exception('Error deleting workspace: ' . $response->body());
}

I receive this response: PowerBINotAuthorizedException

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): How I
  • Low reputation (1):
Posted by: David Monreal