0

Ich möchte lokale Pbix-Datei in den Arbeitsbereich in azure Power BI-Konto zu importieren. Ich habe bereits workspaceId mit der REST API erstellt. Jedoch, wenn ich versuche, pbix-Datei zu importieren, die 200 OK-Status anstelle von 202 gibt akzeptierte Antwort mit ID.Importieren Sie .pbix (power BI) -Datei in den Arbeitsbereich mit PHP (mehrteilige Form-Daten Post)

Hier ist der Referenzcode i enter link description here gefolgt

POST https://api.powerbi.com/v1.0/collections/mypbiapp/workspaces/32960a09-6366-4208-a8bb-9e0678cdbb9d/imports?datasetDisplayName=mydataset01 Berechtigung: AppKey MpaUgrTv5e ... Content-Type: multipart/form-data; boundary = "A300testx"

--A300testx Content-Disposition: form-data

{der Inhalt (binär) .pbix Datei} --A300testx--

ich php verwendet curl Anfrage genannt REST-API und zeigt den Code, die ich versuchte,

$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); 

als Antwort ich bin Statuscode 200 ok mit json bekommen

{ "id": "0331a80d-6f23-4626-9624-1f6b98ce373a"}

jedoch diese neue Datensatz wurde nicht in workspaceID erstellt. Bitte helfen Sie mir, das Problem hier zu finden.

Antwort

2

Hier ist die Antwort für multi form-data Post mit php curl ist, funktioniert dieser Code für mich

$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); 
0

ist hier eine fertige Version der gegebenen Lösung verwenden

public function import($access_key, $workspace_collection_name, $workspace_id, $file_path, $file_name, $display_name, $nameConflict = 'Overwrite') 
{ 

    $boundary = "----------BOUNDARY"; 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://api.powerbi.com/v1.0/collections/$workspace_collection_name/workspaces/$workspace_id/imports?datasetDisplayName=$display_name&nameConflict=$nameConflict"); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $postdata = ''; 
    $postdata .= "--" . $boundary . "\r\n"; 
    $postdata .= "Content-Disposition: form-data; name=\"" . $file_name . "\"; filename=\"" . $file_path . "\"\r\n"; 
    $postdata .= "Content-Type: application/octet-stream\r\n\r\n"; 
    $postdata .= file_get_contents($file_path); 
    $postdata .= "\r\n"; 
    $postdata .= "--" . $boundary . "--\r\n"; 

    curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
     "Authorization: AppKey " . $access_key, 
     'Content-Type: multipart/form-data; boundary=' . $boundary, 
     'Content-Length: ' . strlen($postdata) 
    )); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    $response = curl_exec($ch); 
    if (curl_error($ch)) { 
     return 'curl error'; 
    } 
    curl_close($ch); 

    return $response; 

}