i'm currently developing a Powershell script to refresh a single table partition of my Power BI dataset using a POST API call through the Invoke-RestMethod.
# Connect the Service Principal
$password = ConvertTo-SecureString $Secret -AsPlainText -Force
$Creds = New-Object PSCredential $AppId, $password
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $Creds -Tenant $TenantId
$headers = Get-PowerBIAccessToken
#These refreshes are examples to use the API using the Invole-RestMethod function.
$uri = "https://api.powerbi.com/v1.0/myorg/groups/$GroupId/datasets/$DatasetId"
$DatasetName = (Invoke-RestMethod -Uri $uri –Headers $headers –Method GET | ConvertTo-Json | ConvertFrom-Json | Select name).name
$Query = @"
{
"type": "full",
"commitMode": "transactional",
"objects": [
{
"database": "$DatasetName",
"table": "$TableName",
}
],
"applyRefreshPolicy": "false"
}
"@
# Optional
# Refresh the dataset
$uri = $uri+"/refreshes"
Invoke-RestMethod -Uri $uri –Headers $headers –Method POST -Body ($Query | ConvertTo-Json ) -ContentType "application/json" -ErrorAction Stop
# Check the refresh history
Invoke-RestMethod -Uri $uri –Headers $headers –Method GET | ConvertTo-Json | ConvertFrom-Json | Select -ExpandProperty value | Format-Table -Property id, refreshType, startTime, endTime, status
Disconnect-PowerBIServiceAccount
The Invoke-RestMethod with post request doesn't read the query and start a full refresh on my Power BI dataset. I got no error but a full refresh instead of a specific table refresh.
Is there something wrong that doesn't allow the script to pass and then execute the predefined query instead a full refresh?