<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Not giving token 403 error in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Not-giving-token-403-error/m-p/3240062#M42716</link>
    <description>&lt;P&gt;I've looked through all the forums I've found, but I haven't seen a solution.&lt;/P&gt;&lt;P&gt;The problem is that I am using the given code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;        $curlPostToken = curl_init();
        $clientId = "******";
        $clientSecretId = "******";
        $tenantId = "******";
        $workspace = "******";
        $ReportId = "******";
        
        curl_setopt_array($curlPostToken, array(
            CURLOPT_URL =&amp;gt; "https://login.microsoftonline.com/$tenantId/oauth2/token",            
            CURLOPT_RETURNTRANSFER =&amp;gt; true,
            CURLOPT_ENCODING =&amp;gt; "",
            CURLOPT_MAXREDIRS =&amp;gt; 10,
            CURLOPT_SSL_VERIFYHOST =&amp;gt; false,
            CURLOPT_SSL_VERIFYPEER =&amp;gt; false,
            CURLOPT_TIMEOUT =&amp;gt; 30,
            CURLOPT_HTTP_VERSION =&amp;gt; CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST =&amp;gt; "POST",
            CURLOPT_POSTFIELDS =&amp;gt; array(
                'grant_type' =&amp;gt; 'client_credentials',
                'scope' =&amp;gt; '.default',
                'resource' =&amp;gt; 'https://analysis.windows.net/powerbi/api',
                'tenant_id' =&amp;gt; $tenantId,                
                'client_id' =&amp;gt; $clientId, // Registered App Application ID                
                'client_secret' =&amp;gt; $clientSecretId,                
            )
        ));

        $tokenResponse = curl_exec($curlPostToken);
        $tokenError = curl_error($curlPostToken);
		
        echo $tokenError;
        // decode result, and store the access_token in $embeddedToken variable:
        $tokenResult = json_decode($tokenResponse, true);
        $token = $tokenResult["access_token"];
        $bearerToken = "Bearer "  . ' ' .  $token;
       
        $post_params = array(
            "reports" =&amp;gt; Array(                
                Array('id'=&amp;gt;$ReportId),

            ),
            "accessLevel"=&amp;gt;"View",
        );

        $payload = json_encode($post_params);        
        
		$headers = array(
		"Content-Type: application/json",
		"Authorization: Bearer $access_token"
		);

		$url = "https://api.powerbi.com/v1.0/myorg/groups/$workspace/reports/$ReportId/GenerateToken";

		$ch2 = curl_init( $url );
		curl_setopt( $ch2, CURLINFO_HEADER_OUT, true);
		curl_setopt( $ch2, CURLOPT_POSTFIELDS, $payload);
		curl_setopt( $ch2, CURLOPT_HTTPHEADER, $headers );
		curl_setopt( $ch2, CURLOPT_RETURNTRANSFER, true);
		curl_setopt( $ch2, CURLOPT_FAILONERROR, true);
		$response = curl_exec( $ch2 );
        
		if (curl_errno($ch2)) {
			$error_msg = curl_error($ch2);
		}
		echo $response;
		curl_close($ch2);

		if (isset($error_msg)) {
			echo $error_msg;
		}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Added application as (service principal).&lt;BR /&gt;Issued permissions.&lt;BR /&gt;Added a service principal to Power Bi Workspace Access.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot_1.png" style="width: 200px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/916058i6AA8179EBFF1A149/image-size/small?v=v2&amp;amp;px=200" role="button" title="Screenshot_1.png" alt="Screenshot_1.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot_3.png" style="width: 200px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/916057i987ACED1C3BF5615/image-size/small?v=v2&amp;amp;px=200" role="button" title="Screenshot_3.png" alt="Screenshot_3.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot_2.png" style="width: 200px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/916059i9B1B7AD4F310B4BF/image-size/small?v=v2&amp;amp;px=200" role="button" title="Screenshot_2.png" alt="Screenshot_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But no matter what I do, no matter how I twist the settings, I always get an error:&amp;nbsp;&lt;SPAN&gt;The requested URL returned error: 403&lt;/SPAN&gt;&lt;BR /&gt;I'm already crazy about this problem.&lt;BR /&gt;Help me &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 17 May 2023 11:32:45 GMT</pubDate>
    <dc:creator>MarkLuprin</dc:creator>
    <dc:date>2023-05-17T11:32:45Z</dc:date>
    <item>
      <title>Not giving token 403 error</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Not-giving-token-403-error/m-p/3240062#M42716</link>
      <description>&lt;P&gt;I've looked through all the forums I've found, but I haven't seen a solution.&lt;/P&gt;&lt;P&gt;The problem is that I am using the given code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;        $curlPostToken = curl_init();
        $clientId = "******";
        $clientSecretId = "******";
        $tenantId = "******";
        $workspace = "******";
        $ReportId = "******";
        
        curl_setopt_array($curlPostToken, array(
            CURLOPT_URL =&amp;gt; "https://login.microsoftonline.com/$tenantId/oauth2/token",            
            CURLOPT_RETURNTRANSFER =&amp;gt; true,
            CURLOPT_ENCODING =&amp;gt; "",
            CURLOPT_MAXREDIRS =&amp;gt; 10,
            CURLOPT_SSL_VERIFYHOST =&amp;gt; false,
            CURLOPT_SSL_VERIFYPEER =&amp;gt; false,
            CURLOPT_TIMEOUT =&amp;gt; 30,
            CURLOPT_HTTP_VERSION =&amp;gt; CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST =&amp;gt; "POST",
            CURLOPT_POSTFIELDS =&amp;gt; array(
                'grant_type' =&amp;gt; 'client_credentials',
                'scope' =&amp;gt; '.default',
                'resource' =&amp;gt; 'https://analysis.windows.net/powerbi/api',
                'tenant_id' =&amp;gt; $tenantId,                
                'client_id' =&amp;gt; $clientId, // Registered App Application ID                
                'client_secret' =&amp;gt; $clientSecretId,                
            )
        ));

        $tokenResponse = curl_exec($curlPostToken);
        $tokenError = curl_error($curlPostToken);
		
        echo $tokenError;
        // decode result, and store the access_token in $embeddedToken variable:
        $tokenResult = json_decode($tokenResponse, true);
        $token = $tokenResult["access_token"];
        $bearerToken = "Bearer "  . ' ' .  $token;
       
        $post_params = array(
            "reports" =&amp;gt; Array(                
                Array('id'=&amp;gt;$ReportId),

            ),
            "accessLevel"=&amp;gt;"View",
        );

        $payload = json_encode($post_params);        
        
		$headers = array(
		"Content-Type: application/json",
		"Authorization: Bearer $access_token"
		);

		$url = "https://api.powerbi.com/v1.0/myorg/groups/$workspace/reports/$ReportId/GenerateToken";

		$ch2 = curl_init( $url );
		curl_setopt( $ch2, CURLINFO_HEADER_OUT, true);
		curl_setopt( $ch2, CURLOPT_POSTFIELDS, $payload);
		curl_setopt( $ch2, CURLOPT_HTTPHEADER, $headers );
		curl_setopt( $ch2, CURLOPT_RETURNTRANSFER, true);
		curl_setopt( $ch2, CURLOPT_FAILONERROR, true);
		$response = curl_exec( $ch2 );
        
		if (curl_errno($ch2)) {
			$error_msg = curl_error($ch2);
		}
		echo $response;
		curl_close($ch2);

		if (isset($error_msg)) {
			echo $error_msg;
		}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Added application as (service principal).&lt;BR /&gt;Issued permissions.&lt;BR /&gt;Added a service principal to Power Bi Workspace Access.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot_1.png" style="width: 200px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/916058i6AA8179EBFF1A149/image-size/small?v=v2&amp;amp;px=200" role="button" title="Screenshot_1.png" alt="Screenshot_1.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot_3.png" style="width: 200px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/916057i987ACED1C3BF5615/image-size/small?v=v2&amp;amp;px=200" role="button" title="Screenshot_3.png" alt="Screenshot_3.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot_2.png" style="width: 200px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/916059i9B1B7AD4F310B4BF/image-size/small?v=v2&amp;amp;px=200" role="button" title="Screenshot_2.png" alt="Screenshot_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But no matter what I do, no matter how I twist the settings, I always get an error:&amp;nbsp;&lt;SPAN&gt;The requested URL returned error: 403&lt;/SPAN&gt;&lt;BR /&gt;I'm already crazy about this problem.&lt;BR /&gt;Help me &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2023 11:32:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Not-giving-token-403-error/m-p/3240062#M42716</guid>
      <dc:creator>MarkLuprin</dc:creator>
      <dc:date>2023-05-17T11:32:45Z</dc:date>
    </item>
  </channel>
</rss>

