# Error 400 Script PowerShell? This script try to import a Dataflow in a Workspace

**URL:** <https://forums.powershell.org/t/error-400-script-powershell-this-script-try-to-import-a-dataflow-in-a-workspace/20414>\
**Category:** PowerShell Help\
**Created:** [September 14, 2022, 7:00am UTC](https://forums.powershell.org/t/error-400-script-powershell-this-script-try-to-import-a-dataflow-in-a-workspace/20414 "2022-09-14T07:00:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cha74](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Cha74](https://forums.powershell.org/u/Cha74)\
**Post date:** [September 14, 2022, 7:00am UTC](https://forums.powershell.org/t/error-400-script-powershell-this-script-try-to-import-a-dataflow-in-a-workspace/20414/1 "2022-09-14T07:00:46Z")

</div>

```auto
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "...", ("..." | ConvertTo-SecureString -AsPlainText -Force)

Connect-PowerBIServiceAccount -ServicePrincipal -Tenant "..." -Credential $credential -Environment "Public"

$workspaceName = "WKS - DTS [DEV]"

$DataflowImportFileName = "C:\Users\cbonier\Documents\DTF FINANCE.json"

$DataflowDefinition = [IO.File]::ReadAllText($DataflowImportFileName)

$UserAccessToken = Get-PowerBIAccessToken
$bearer = $UserAccessToken.Authorization.ToString()

$workspace = Get-PowerBIWorkspace -Name $workspaceName
$workspaceId = $workspace.Id

$importsUrl = "https://api.powerbi.com/v1.0/myorg/groups/$workspaceId/imports?datasetDisplayName=DTF FINANCE.json"

$boundary = [System.Guid]::NewGuid().ToString("N")
$LF = [System.Environment]::NewLine

$contentType = "multipart/from-data; boundary=""$boundary"""

$body = (
"--$boundary",
"Content-Disposition: form-data $LF",
$DataflowDefinition,
"--$boundary--$LF"
) -join $LF

$header = @{
    'Authorization' = "$bearer"
    'Content-Type' = "$contentType"
}

Invoke-RestMethod -Uri $importsUrl -ContentType $contentType -Method Post -Headers $header -Body $body

```

Error :

```auto
Invoke-RestMethod : Le serveur distant a retourné une erreur : (400) Demande incorrecte.
Au caractère Ligne:38 : 1
+ Invoke-RestMethod -Uri $importsUrl -ContentType $contentType -Method ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation : (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

```

This script aims to import a dataflow into a workspace in Power BI Service.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:16pm UTC](https://forums.powershell.org/t/error-400-script-powershell-this-script-try-to-import-a-dataflow-in-a-workspace/20414/2 "2024-05-16T20:16:37Z")

</div>

Closed on May 16, 2024, 8:16pm UTC


