Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
bright
Helper I
Helper I

Powerbi api create dataset http respond Forbidden 403

Help , i use php creat dataset send request but http respond 403 i can't creat dataset on my powerbi 

<?php
session_start();
$token = $_GET['code'];
$session_state = $_GET['session_state'];
$tablename = $_SESSION['CustomerId'];
$columns[] = array(
'name'=>'PorductID',
'type'=>'Text',
);
$columns[] = array(
'name'=>'Name',
'type'=>'Text',
);
$columns[] = array(
'name'=>'Number',
'type'=>'Number',
);
$columns[] = array(
'name'=>'Price',
'type'=>'Number',
);
$columns[] = array(
'name'=>'MenuId',
'type'=>'Text',
);
$columns[] = array(
'name'=>'PurchaseTime',
'type'=>'DateTime',	
);
$table = array(
'name'=>$tablename,
'columns'=>	$columns,
);
$data = array(
'name'=>'Client',
'table'=>$table,
);
$data = utf8_encode(json_encode($data));
$url ="https://api.powerbi.com/v1.0/myorg/datasets";
// build datasets , reference information https://powerbi.microsoft.com/zh-tw/documentation/powerbi-developer-walkthrough-push-data-create-dataset/
$header[] ="ContentLength:0";
$header[] ="Content-Type:application/json";
$headr[] = "Authorization:$token";
$ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
	  curl_setopt($ch,CURLOPT_FORBID_REUSE ,true);
	  curl_setopt($ch, CURLOPT_POST, true);
	  curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
	  $output = curl_exec($ch);
      $error = curl_error($ch);
      $http = curl_getinfo($ch,CURLINFO_HTTP_CODE);
	  curl_close($ch);
	  echo $http;
      if($http>300){
		  exit('操作失敗');
	  }
	  echo$output;

?>
2 ACCEPTED SOLUTIONS

@bright

 

What is the $token like in your case? it should be something like "Bearer tokenstring". You can test the REST API alone via POSTMAN.

 

$token = $_GET['code']; 
.
.
$headr[] = "Authorization:$token";

View solution in original post

session_start();
	$access = $this->token();
	$token_type = $access->token_type;
    $token = $access->access_token;	
	date_default_timezone_set('UTC');
	$date = date('D , d M Y	H:i:s');
	//Sun, 20 Sep 2009 20:36:40 GMT
	
	$tablename = 'info';
	
	
	$columns[] = array(
	'name'=>'Number',
	'dataType'=>'Int64',
	);
	$columns[] = array(
	'name'=>'ClinetId',
	'dataType'=>'Int64',
	);
	$columns[] = array(
	'name'=>'Price',
	'dataType'=>'Int64',
	);
	$columns[] = array(
	'name'=>'MenuId',
	'dataType'=>'string',
	);
	$columns[] = array(
	'name'=>'PurchaseTime',
	'dataType'=>'DateTime',	
	);
	
	$table = array(
	'name'=>$tablename,
	'columns'=>	$columns,
	);
	$data = array(
	'name'=>'Client',
	'tables'=>array($table),
	);

	$url ="https://api.PowerBI.com/v1.0/myorg/datasets";
	 $header[] ="Authorization:$token_type $token";
	$header[] ="Content-Type: application/json";
	$header[]= "content_length:0";
	$data1 = utf8_encode(json_encode($data));
	$res  = $this->get_respond('creat',$data1,$header,$url);
	return $res;

  I find error my cloumn setting woring 

View solution in original post

5 REPLIES 5
bright
Helper I
Helper I

HTTP/1.1 403 Forbidden
Content-Length: 0
Server: Microsoft-HTTPAPI/2.0
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Frame-Options: deny
X-Content-Type-Options: nosniff
RequestId: cbd09b84-064f-4257-b35d-9c9bb4a6d70a
Date: Fri, 14 Oct 2016 06:15:04 GMT

server respond massage 

@bright

 

What is the $token like in your case? it should be something like "Bearer tokenstring". You can test the REST API alone via POSTMAN.

 

$token = $_GET['code']; 
.
.
$headr[] = "Authorization:$token";

session_start();
	$access = $this->token();
	$token_type = $access->token_type;
    $token = $access->access_token;	
	date_default_timezone_set('UTC');
	$date = date('D , d M Y	H:i:s');
	//Sun, 20 Sep 2009 20:36:40 GMT
	
	$tablename = 'info';
	
	
	$columns[] = array(
	'name'=>'Number',
	'dataType'=>'Int64',
	);
	$columns[] = array(
	'name'=>'ClinetId',
	'dataType'=>'Int64',
	);
	$columns[] = array(
	'name'=>'Price',
	'dataType'=>'Int64',
	);
	$columns[] = array(
	'name'=>'MenuId',
	'dataType'=>'string',
	);
	$columns[] = array(
	'name'=>'PurchaseTime',
	'dataType'=>'DateTime',	
	);
	
	$table = array(
	'name'=>$tablename,
	'columns'=>	$columns,
	);
	$data = array(
	'name'=>'Client',
	'tables'=>array($table),
	);

	$url ="https://api.PowerBI.com/v1.0/myorg/datasets";
	 $header[] ="Authorization:$token_type $token";
	$header[] ="Content-Type: application/json";
	$header[]= "content_length:0";
	$data1 = utf8_encode(json_encode($data));
	$res  = $this->get_respond('creat',$data1,$header,$url);
	return $res;

  I find error my cloumn setting woring 

thank you eric_zhang i have been slove 

bright
Helper I
Helper I

it is my json code

{"name":"Client","table":{"name":"1467e0ce-1452-4f96-b830-ade8dcb47c38","columns":[{"name":"PorductID","type":"Text"},{"name":"Name","type":"Text"},{"name":"Number","type":"Number"},{"name":"Price","type":"Number"},{"name":"MenuId","type":"Text"},{"name":"PurchaseTime","type":"DateTime"},{"name":"SPN","type":"Text"}]}}

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.