最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

powershell - Fabric-Rest API: why updateFromGit is returning invalid git hash or missing options? - Stack Overflow

programmeradmin2浏览0评论

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 = '/{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 = '/{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?

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?

Share Improve this question edited yesterday VLAZ 29k9 gold badges62 silver badges83 bronze badges asked 2 days ago AleixAleix 4515 silver badges24 bronze badges 2
  • Are you getting 200/201 as response or 202. Read the LRO link in your link "here". – jdweng Commented 2 days ago
  • Are you still facing the issue. – Jahnavi Commented 22 hours ago
Add a comment  | 

1 Answer 1

Reset to default 0

Adding the parameter -ContentType application/json using Invoke-RestMethod let the request be processed correctly when body was parsed as JSON.

发布评论

评论列表(0)

  1. 暂无评论