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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

[REST API] Datasets Take Over: Positional Parameter cannot be found that accepts argument 'Method'

Getting the following error when trying to take over dataset using this REST API: https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/take-over-in-group

 

smohanty_0-1637742722953.png

 

Following is my code:


#Login using Service Principal
#-------------------------------
cls
$applicationId = "XXXXX"
$clientsec = "XXXXX" | ConvertTo-SecureString -AsPlainText -Force #
$tenantId = "XXXXX"
$resource = "https://analysis.windows.net/powerbi/api"

$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $clientsec
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId $tenantId

# Get token
#-------------------------------
$token = Get-PowerBIAccessToken -AsString



# Building Rest API header with authorization token
#-------------------------------
$authHeader = @{
'Content-Type'='application/json'
'Authorization'=$token
}

#Group and Dataset Parameters
#-------------------------------
$group= "xxxxx" #workspace ID
$dataset= "xxxxxx" #dataset ID


# POST body
#-------------------------------
$postParams = @{
"datasetId" = "$dataset"
}
$jsonPostBody = $postParams | ConvertTo-JSON

$Url = "https://api.powerbi.com/v1.0/myorg/groups/$group/datasets/$dataset/Default.TakeOver"


## Take Over DataSet
#-------------------------------
Invoke-PowerBIRestMethod -Url $Url -Headers $authHeader -Body $jsonPostBody Method -POST -Verbose

 The Service Principal has the following permissions:

 

smohanty_1-1637743057259.png

What am I missing? Please help! Thanks in advance.

 

8 REPLIES 8
lbendlin
Super User
Super User

@Anonymous instead of 

 

Method -Post

 

you need 

 

-Method POST

Anonymous
Not applicable

Getting the same error after replacing -POST with POST:

 

smohanty_0-1638194520499.png

 

Please read my reply again.  Use -Method  (note the dash)

Anonymous
Not applicable

Thank you, I changed the code but getting this new error now:

Invoke-PowerBIRestMethod -Url $Url -Headers $authHeader -Body $jsonPostBody -Method POST -Verbose

smohanty_0-1638196040196.png

 

Looks like 

 

Get-PowerBIAccessToken -AsString

 returns more than you need. Investigate that and then only use the auth part.

 

most likely

$authHeader = @{
'Content-Type'='application/json'
'Authorization'=$token.Values[0]
}

 

Hmm, maybe the issue is elsewhere. Both

 

Connect-PowerBIServiceAccount
$headers = Get-PowerBIAccessToken -AsString
$authHeader = @{
'Content-Type'='application/json'
'Authorization'=$headers
}
Invoke-RestMethod -Headers $authHeader -Uri 'https://api.powerbi.com/v1.0/myorg/groups'

 

and 

 

Connect-PowerBIServiceAccount
$headers = Get-PowerBIAccessToken 
Invoke-RestMethod -Headers $headers -Uri 'https://api.powerbi.com/v1.0/myorg/groups'

 

work for me.

 

Maybe Invoke-PowerBIRestMethod is the culprit.  Use Invoke-RestMethod instead.

Anonymous
Not applicable

Tried this code:

Invoke-RestMethod -Uri $Url -Headers $authHeader -Body $jsonPostBody -Method POST -Verbose

Getting the following error now:

smohanty_1-1638205414878.png

 

@Anonymous replace the nonunicode "-" sign and type "-" again to each parameter.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.