<?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 PHP, Curl to get embed token via API GenerateToken returns 404 using service principal in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/PHP-Curl-to-get-embed-token-via-API-GenerateToken-returns-404/m-p/1434051#M26125</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This snippet of code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;?php
/* Get token using a POST request */

$clientId = 'xxx';
$clientSecret = 'xxx';
$tenantId = 'xxxx';
$urlAccessToken = "https://login.windows.net/$tenantId/oauth2/token";
$resource = 'https://analysis.windows.net/powerbi/api';
$group = 'xxx';
$report ='xxx';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://login.microsoftonline.com/$tenantId/oauth2/token");

curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'resource' =&amp;gt; $resource,
'client_id' =&amp;gt; $clientId,
'client_secret' =&amp;gt; $clientSecret,
'grant_type' =&amp;gt; 'client_credentials'
));

$data = curl_exec($ch);
curl_close($ch);

$data_obj = json_decode($data);
$access_token = $data_obj-&amp;gt;{"access_token"};
$headers = array(
"Content-Type: application/json",
"Authorization: Bearer $access_token"
);


$url = "https://api.powerbi.com/v1.0/myorg/groups/$group/reports/$report/GenerateToken";
#$url ="https://api.powerbi.com/v1.0/myorg/groups/$group/reports";
$post_params = array(
'accessLevel' =&amp;gt; 'View'
);

$payload = json_encode($post_params);

$ch2 = curl_init( $url );
curl_setopt( $ch2, CURLOPT_POST, true);
curl_setopt( $ch2, CURLINFO_HEADER_OUT, true);
curl_setopt( $ch2, CURLOPT_POST, $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;
}

?&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Authenticates properly (getting us an access token), then attempts call GenerateToken using that access token. It authenticates fine, but ALWAYS returns 404. I know the reports are there, and that the ids are correct because we can interrogate the reports using this snippet (and the same authtoken):&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;$url ="https://api.powerbi.com/v1.0/myorg/groups/$group/reports";
$headers = array(
   "Content-Type: application/json",
   "Authorization: Bearer $access_token"
);

$payload = json_encode($post_params);

$ch2 = curl_init( $url );
curl_setopt( $ch2, CURLOPT_POST, true);
curl_setopt( $ch2, CURLINFO_HEADER_OUT, true);
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);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and get back the proper looking JSON for all the reports in the workspace in question. So we know the auth works, we know the accesstoken has access to the workspace--why am I getting a 404 back? Ive double and triple checked the ids against the JSON returned by the reports list API. Totally stumped.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Oct 2020 18:50:34 GMT</pubDate>
    <dc:creator>wingmanzz</dc:creator>
    <dc:date>2020-10-14T18:50:34Z</dc:date>
    <item>
      <title>PHP, Curl to get embed token via API GenerateToken returns 404 using service principal</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/PHP-Curl-to-get-embed-token-via-API-GenerateToken-returns-404/m-p/1434051#M26125</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This snippet of code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;?php
/* Get token using a POST request */

$clientId = 'xxx';
$clientSecret = 'xxx';
$tenantId = 'xxxx';
$urlAccessToken = "https://login.windows.net/$tenantId/oauth2/token";
$resource = 'https://analysis.windows.net/powerbi/api';
$group = 'xxx';
$report ='xxx';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://login.microsoftonline.com/$tenantId/oauth2/token");

curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'resource' =&amp;gt; $resource,
'client_id' =&amp;gt; $clientId,
'client_secret' =&amp;gt; $clientSecret,
'grant_type' =&amp;gt; 'client_credentials'
));

$data = curl_exec($ch);
curl_close($ch);

$data_obj = json_decode($data);
$access_token = $data_obj-&amp;gt;{"access_token"};
$headers = array(
"Content-Type: application/json",
"Authorization: Bearer $access_token"
);


$url = "https://api.powerbi.com/v1.0/myorg/groups/$group/reports/$report/GenerateToken";
#$url ="https://api.powerbi.com/v1.0/myorg/groups/$group/reports";
$post_params = array(
'accessLevel' =&amp;gt; 'View'
);

$payload = json_encode($post_params);

$ch2 = curl_init( $url );
curl_setopt( $ch2, CURLOPT_POST, true);
curl_setopt( $ch2, CURLINFO_HEADER_OUT, true);
curl_setopt( $ch2, CURLOPT_POST, $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;
}

?&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Authenticates properly (getting us an access token), then attempts call GenerateToken using that access token. It authenticates fine, but ALWAYS returns 404. I know the reports are there, and that the ids are correct because we can interrogate the reports using this snippet (and the same authtoken):&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;$url ="https://api.powerbi.com/v1.0/myorg/groups/$group/reports";
$headers = array(
   "Content-Type: application/json",
   "Authorization: Bearer $access_token"
);

$payload = json_encode($post_params);

$ch2 = curl_init( $url );
curl_setopt( $ch2, CURLOPT_POST, true);
curl_setopt( $ch2, CURLINFO_HEADER_OUT, true);
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);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and get back the proper looking JSON for all the reports in the workspace in question. So we know the auth works, we know the accesstoken has access to the workspace--why am I getting a 404 back? Ive double and triple checked the ids against the JSON returned by the reports list API. Totally stumped.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 18:50:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/PHP-Curl-to-get-embed-token-via-API-GenerateToken-returns-404/m-p/1434051#M26125</guid>
      <dc:creator>wingmanzz</dc:creator>
      <dc:date>2020-10-14T18:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: PHP, Curl to get embed token via API GenerateToken returns 404 using service principal</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/PHP-Curl-to-get-embed-token-via-API-GenerateToken-returns-404/m-p/1437133#M26149</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/260658"&gt;@wingmanzz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Of course you shouldn't get a 404 if the resource was found so that's odd.&lt;/P&gt;&lt;P&gt;Once you've got a valid access token you can try using Postman to issue the GenerateToken request and see what is happening.&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.postman.com/" target="_blank"&gt;https://www.postman.com/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Phil&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 01:28:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/PHP-Curl-to-get-embed-token-via-API-GenerateToken-returns-404/m-p/1437133#M26149</guid>
      <dc:creator>PhilipTreacy</dc:creator>
      <dc:date>2020-10-16T01:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: PHP, Curl to get embed token via API GenerateToken returns 404 using service principal</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/PHP-Curl-to-get-embed-token-via-API-GenerateToken-returns-404/m-p/1447601#M26215</link>
      <description>&lt;P class="lia-align-justify"&gt;So we dug into this a little bit more and were able to debug it..it was an error in the curl_setopts. posting fixed code here, in case anyone runs across this issue.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;&amp;lt;?php
/* Get token using a POST request */

$clientId = 'xxx';
$clientSecret = 'xxx';
$tenantId = 'xxxx';
$urlAccessToken = "https://login.windows.net/$tenantId/oauth2/token";
$resource = 'https://analysis.windows.net/powerbi/api';
$group = 'xxx';
$report ='xxx';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://login.microsoftonline.com/$tenantId/oauth2/token");

curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'resource' =&amp;gt; $resource,
'client_id' =&amp;gt; $clientId,
'client_secret' =&amp;gt; $clientSecret,
'grant_type' =&amp;gt; 'client_credentials'
));

$data = curl_exec($ch);
curl_close($ch);

$data_obj = json_decode($data);
$access_token = $data_obj-&amp;gt;{"access_token"};
$headers = array(
"Content-Type: application/json",
"Authorization: Bearer $access_token"
);


$url = "https://api.powerbi.com/v1.0/myorg/groups/$group/reports/$report/GenerateToken";
#$url ="https://api.powerbi.com/v1.0/myorg/groups/$group/reports";
$post_params = array(
'accessLevel' =&amp;gt; 'View'
);

$payload = json_encode($post_params);

$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;
}

?&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 16:53:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/PHP-Curl-to-get-embed-token-via-API-GenerateToken-returns-404/m-p/1447601#M26215</guid>
      <dc:creator>wingmanzz</dc:creator>
      <dc:date>2020-10-21T16:53:25Z</dc:date>
    </item>
  </channel>
</rss>

