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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

PowerBI API Dataset Refresh 404 Not Found

Hi!


I am currently using PowerShell to make an API call to refresh a dataset. Here is the code:

 

 

# Credentials
$AppId = "<AppId>"
$TenantId = "<TenantId>"
$ClientSecret = "<ClientSecret>" 

# Creating secure string & credential for Application ID and client secret
$PbiSecurePassword = ConvertTo-SecureString $ClientSecret -Force -AsPlainText
$PbiCredential = New-Object Management.Automation.PSCredential($AppId, $PbiSecurePassword)

# Connect to the Power BI Service Account
Connect-PowerBIServiceAccount -ServicePrincipal -TenantId $TenantId -Credential $PbiCredential

# Set the value of the Group ID and Dataset Name
$GroupId = '<GroupId>'
$DatasetName = '<DatasetName>'

# Get the Dataset ID of the Target Dataset
$Datasets = Get-PowerBIDataset -WorkspaceId $GroupId
$DatasetId = ($Datasets | Where-Object { $_.Name -eq $DatasetName }).Id.Guid

Write-Host $DatasetId

# Refresh the Dataset
try {
    $Headers = Get-PowerBIAccessToken
    Invoke-RestMethod -Headers $Headers -Uri "https://api.powerbi.com/v1.0/myorg/groups/${GroupId}/datasets/${DatasetId}/refreshes" -Method 'Post' -Body ([pscustomobject]@{type='full'; commitMode='transactional'; applyRefreshPolicy='true'; notifyOption='MailOnCompletion'} | ConvertTo-Json -Depth 2 -Compress)
    Write-Output "Successfully triggered a PowerBI Dataset Refresh."
} catch {
    if ($_.Exception.Response.StatusCode.value__ -eq 400) {
        Write-Output "A refresh is currently running."
        $RefreshStatus = Invoke-RestMethod -Headers $Headers -Uri "https://api.powerbi.com/v1.0/myorg/groups/${GroupId}/datasets/${DatasetId}/refreshes" -Method 'Get'
        
        $LatestRefresh = $RefreshStatus.value[0]
        $Status = $LatestRefresh.status
        $StartTime = $LatestRefresh.startTime
        $EndTime = $LatestRefresh.endTime
        
        $Output = @"
        Status: $Status
        Start Time: $StartTime
        End Time: $EndTime
"@
        Write-Output $Output

    } else {
        Write-Output "An error occurred: $($_.Exception.Message)"
    }
}

 

 

 
The script works as intended when running locally. If the dataset is not being refreshed currently then a refresh is triggered. If the dataset is currently being refreshed then the status is displayed. However, I am trying to deploy this to an automation software called ActiveBatch which allows you to schedule and trigger PowerShell jobs. 

When I run the job on ActiveBatch, the job fails with a 404 Error. Specifically the following:

 

 

The remote server returned an error: (404) Not Found.

 

 

The service account has access to the dataset and there is no permissions issue. I saw a similar post regarding this which said that this is an issue related to AD group permissions. However, that is not the case here since the service account is added as an Admin to the dataset and the script works as intended locally. 

 

What is strange is that the script works fine when I am running it on my laptop but it fails when running on ActiveBatch using the same service account credentials.

Thank you in advance!

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous ,

Based on the information you've provided, it seems like your PowerShell script works as expected when executed locally but encounters a 404 Not Found error when scheduled and run through ActiveBatch. This discrepancy suggests that the issue might not be with the script itself but rather with how ActiveBatch interacts with the Power BI API or the environment it's running in.

 

A few areas to investigate:

1. Endpoint Accessibility: Ensure that the ActiveBatch environment has network access to api.powerbi.com. It's possible that network policies or firewalls in the ActiveBatch environment are blocking access to the Power BI API endpoints.

 

2. PowerShell Environment: Verify that the PowerShell version and modules available in the ActiveBatch environment are the same as those on your local machine. Differences in PowerShell versions or missing modules could lead to unexpected behavior.

 

3. Service Principal Permissions: Double-check that the service principal used has the necessary API permissions assigned in Azure AD and that it's not restricted in any way when running from the ActiveBatch environment.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.