Forum Discussion
adamwallace3
Advocate II
8 years agoHow To: Get embed token using Get/Post only
Step 1: Authorize App Register App I used a native app, it was the simplest solution. You can use a server-web app, but you will need to add client_secret anywhere you see client_id in this walk...
Anonymous
7 years agoNot applicable
Hi there, I am trying to embed report with PHP curl. I got everything working, but when I am trying to implement row level security I got stuck.
First I get access token (this works):
$curl1 = curl_init(); curl_setopt_array($curl1, array(CURLOPT_URL => "https://login.windows.net/common/oauth2/token", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => array( 'grant_type' => 'password', 'scope' => 'openid', 'resource' => 'https://analysis.windows.net/powerbi/api', 'client_id' => '0aa12345-1234-1234-1234-123412341234', // registered App ApplicationID 'username' => '[email protected]', // your Power BI Pro account, e.g. [email protected] 'password' => 'mysecretpassword' // password for above user ) )); $tokenResponse = curl_exec($curl1); $tokenError = curl_error($curl1); curl_close($curl1); $tokenResult = json_decode($tokenResponse, true); $token = $tokenResult["access_token"]; $embeddedToken = "Bearer " . ' ' . $token;
With this access token I should be able to create embed token with RLS for each user BUT it doesn't work:
$curl3 = curl_init();
curl_setopt($curl3, CURLOPT_URL, 'https://api.powerbi.com/v1.0/myorg/groups/'.$group_Id.'/reports/'.$report_ID.'/GenerateToken');
curl_setopt($curl3, CURLOPT_RETURNTRANSFER, TRUE);
//curl_setopt($curl3, CURLOPT_SSL_VERIFYPEER, false); //Might be required for https
curl_setopt($curl3, CURLOPT_ENCODING, "");
curl_setopt($curl3, CURLOPT_MAXREDIRS, 10);
curl_setopt($curl3, CURLOPT_TIMEOUT, 30);
curl_setopt($curl3, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl3, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt ($curl3, CURLOPT_HTTPHEADER,array(
'Authorization: '.$embeddedToken,
'Content-Type:application/json; charset=utf-8',
'Accept:application/json',
"accessLevel: View",
"username: userOne",
"roles: Tenant",
"datasets: 12345678-1234-1234-1234-123123123"
));
$RLStokenResponse = curl_exec($curl3);
$RLStokenError = curl_error($curl3);
curl_close($curl3);
if ($RLStokenError) {
echo "cURL Error #:" . $RLStokenError;
} else {
$RLStokenResult = json_decode($RLStokenResponse, true);
$RLStoken = $RLStokenResult["access_token"];
$RLSembeddedToken = "Bearer " . ' ' . $RLStoken;
}
This request returns an error. Could you please advise me what I am doing wrong?