我想将本地pbix文件导入到azure power bi帐户中创建的工作区。我已经使用REST API创建了workspaceId。但是,当我尝试导入pbix文件时,提供200 ok状态而不是202已接受的响应ID。
以下是我跟随enter link description here
的参考代码POST https://api.powerbi.com/v1.0/collections/mypbiapp/workspaces/32960a09-6366-4208-a8bb-9e0678cdbb9d/imports?datasetDisplayName=mydataset01 授权:AppKey MpaUgrTv5e ...内容类型:multipart / form-data; 边界=" A300testx"
- A300testx Content-Disposition:form-data
{.pbix文件的内容(二进制)} --A300testx -
我使用php curl请求调用Rest API,下面显示了我尝试的代码,
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.powerbi.com/v1.0/collections/XXXXXX/workspaces/XXX-XXX-XXX-XXXXXXXX/imports?datasetDisplayName=mydataset01');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postData = array(
'datafile' => '@C:\Users\Desktop\report1.pbix',
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt ( $ch, CURLOPT_HTTPHEADER, array (
"Authorization: AppKey R97v4Fe5=="
) );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
echo $response = curl_exec($ch);
curl_close ( $ch );
作为回复,我使用json
获取状态代码为200 ok{" ID":" 0331a80d-6f23-4626-9624-1f6b98ce373a"}
但是,这个新数据集并未在workspaceID中创建。请帮我在这里找到问题。
答案 0 :(得分:2)
以下是使用php curl的多部分表单数据帖子的答案,此代码适用于我
$name = 'report1';
$file = 'report1.pbix';
$boundary = "----------BOUNDARY";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.powerbi.com/v1.0/collections/XXXXXX/workspaces/XXX-XXX-XXX-XXXXXXXX/imports?datasetDisplayName=mydataset01');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postdata .= "--" . $boundary . "\r\n";
$postdata .= "Content-Disposition: form-data; name=\"" . $name . "\"; filename=\"" . $file . "\"\r\n";
$postdata .= "Content-Type: application/octet-stream\r\n\r\n";
$postdata .= file_get_contents($file);
$postdata .= "\r\n";
$postdata .= "--" . $boundary . "--\r\n";
curl_setopt($ch, CURLOPT_POSTFIELDS, $$postdata);
curl_setopt ( $ch, CURLOPT_HTTPHEADER, array (
"Authorization: AppKey R97v4Fe5==",
'Content-Type: multipart/form-data; boundary='.$boundary,
'Content-Length: ' . strlen($postdata)
) );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
echo $response = curl_exec($ch);
curl_close ( $ch );
答案 1 :(得分:0)
这是给定解决方案的即用型版本
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Example</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-6 col-sm-8 col-md-6 col-lg-4">
<img src="http://ia.media-imdb.com/images/M/MV5BMTk2NTI1MTU4N15BMl5BanBnXkFtZTcwODg0OTY0Nw@@._V1_SX300.jpg" class="img-responsive">
</div>
<div class="col-xs-6 col-sm-4 col-md-2 col-lg-2">
<div id="ratingdiv">
<div class="row">
<label>Your Rating</label>
<div id="rateYo"></div>
</div>
<div class="row">
<button type="button" class="btn btn-info btn-md">Edit</button>
<button type="button" class="btn btn-danger btn-md">Delete</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>