I'm sending a POST request using Powershell Invoke-WebRequest to /git/updateFromGit
endpoint of the Fabric Rest API.
Previously, I successfully retrieved the workspace Head and remote Git Hash calling /git/GetStatus
as described here.
My token is a valid one that I checked has the correct scopes.
I cannot send a successful request to update the workspace from git, always having problems with the request body: it either says that is missing some properties or that the git hash is not valid.
This is the part of the code that builds the requests and sends it:
$headers = @{ 'Authorization' = "Bearer $token"}
$urlUpdate = 'https://api.fabric.microsoft.com/v1/workspaces/{0}/git/updateFromGit' -f $workspaceId
$postParams = [ordered]@{
workspaceHead = $GitWorkspaceHead
remoteCommitHash = $GitRemoteCommitHash
options = @{allowOverrideItems = $true }
}
Write-Host "Request body:"
$postParams | Format-Table
$ResponseUpdate = Invoke-WebRequest -Method Post -Uri $urlUpdate -Headers $headers -Body $postParams
In this case, I send $postParams
as a Hash table. The error message I receive is the following:
In a second attempt, I send $postParams
as a JSON object, and in this case it says that the git hash is not valid, but the git hash is correct and valid after checking it.
As you can see the JSON format is identical to the one described in the documentation examples (conflictResolution
is not requiered).
$headers = @{ 'Authorization' = "Bearer $token"}
$urlUpdate = 'https://api.fabric.microsoft.com/v1/workspaces/{0}/git/updateFromGit' -f $workspaceId
$postParams = [ordered]@{
workspaceHead = $GitWorkspaceHead
remoteCommitHash = $GitRemoteCommitHash
options = @{allowOverrideItems = $true }
} | ConvertTo-Json
Write-Host "Request body:"
$postParams | Format-Table
$ResponseUpdate = Invoke-WebRequest -Method Post -Uri $urlUpdate -Headers $headers -Body $postParams
What am I doing wrong?
Adding the parameter -ContentType application/json
using Invoke-RestMethod let the request be processed correctly when body was parsed as JSON.