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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
yazdanb
New Contributor II

Issue with Fabric Git API loop from Azure DevOps

Hi everyone,

 

My team and I are having issues trying to automate Power BI report deployment from Azure DevOps to Microsoft Fabric using the Fabric Git REST APIs. The goal is simple: connect a workspace to an Azure DevOps repo, initialize the connection, and then update from Git.

However, we keep getting stuck in a circular state where the API says the workspace is connected, but it never actually initializes.

 

What happens:

  • POST /git/connect works successfully (or returns โ€œWorkspaceAlreadyConnectedToGitโ€).

  • Immediately after, POST /git/initializeConnection fails every time with:

     
    { "errorCode": "UnknownError", "message": "An unexpected error occurred while processing the request" }
  • Then GET /git/status always returns:

     
    { "errorCode": "WorkspaceGitConnectionNotInitialized" }

So Fabric believes the workspace is connected but also insists itโ€™s not initialized, and weโ€™re stuck in between. Weโ€™ve tried retries, delays, and disconnect/reconnect cycles, nothing moves it past this state.

What weโ€™ve already tried:

  • Disconnecting the workspace (/git/disconnect), waiting 30โ€“60 seconds, reconnecting, and retrying initialization.

  • Polling the connect operation until it reports success before calling initializeConnection.

  • Verifying that:

    • The branch, directory, and repo all exist and are correct.

    • The Fabric service principal (ConfiguredConnection) has access to the Azure DevOps repo.

    • The same connection works fine when done manually via the Fabric UI.

So far, manual connection and sync in the UI works perfectly, but doing the same steps via the API always fails with UnknownError โ†’ WorkspaceGitConnectionNotInitialized.

 

Could you please point me in the right direction as to what can be changed/fixed? I am running into all sorts of circular issues that don't make sense to me. I've tried debugging with this ChatGPT for hours, but to no avail ๐Ÿ˜ž

 

Thank you!

 

Here is the .yml file we are trying:

trigger:
  branches: [Approach-A]

pool:
  vmImage: ubuntu-latest

variables:
  deployRoot: 'deployed'
  firmsRoot: 'Firms'
  firmName: 'Firm A'
  FABRIC_CONNECTION_ID: 'CONNECTION_ID'

stages:
- stage: ComposeAndCommit
  displayName: "Stage 1: Compose + Commit"
  jobs:
  - job: ComposeJob
    steps:
    - checkout: self
    - bash: |
        deployPath="$deployRoot/$firmName"
        rm -rf "$deployPath" && mkdir -p "$deployPath"
        cp -R Main/. "$deployPath/" && cp -R "$firmsRoot/$firmName/." "$deployPath/" || true
        git config user.email "buildagent@local"
        git config user.name "Build Agent"
        git add "$deployRoot/$firmName" || true
        if ! git diff --cached --quiet; then
          git commit -m "[skip ci] Deploy $(firmName)"
          git push origin HEAD:Approach-A
        fi

- stage: GitSync
  displayName: "Stage 2: Fabric Sync"
  jobs:
  - job: SyncJob
    steps:
    - pwsh: |
        $tenantId     = "$(TENANT_ID)"
        $clientId     = "$(CLIENT_ID)"
        $clientSecret = "$(CLIENT_SECRET)"
        $workspaceId  = "$(WORKSPACE_ID)"
        $connectionId = "$(FABRIC_CONNECTION_ID)"
        $org = "ORG_NAME"
        $project = "PROJECT_NAME"
        $repo = "REPO_NAME"
        $branch = "Approach-A"
        $directory = "deployed/Firm A"

        # Token
        $tokenBody = @{
          client_id = $clientId; scope = "https://api.fabric.microsoft.com/.default"
          client_secret = $clientSecret; grant_type = "client_credentials"
        }
        $token = (Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" -Method Post -Body $tokenBody).access_token
        $headers = @{ Authorization = "Bearer $token"; "Content-Type" = "application/json" }

        # Connect
        $connectUri = "https://api.fabric.microsoft.com/v1/workspaces/$workspaceId/git/connect"
        $body = @{
          gitProviderDetails = @{
            gitProviderType="AzureDevOps"; organizationName=$org; projectName=$project
            repositoryName=$repo; branchName=$branch; directoryName=$directory }
          myGitCredentials = @{ source="ConfiguredConnection"; connectionId=$connectionId }
          itemSyncMode="Mirror"
        }
        try {
          Invoke-RestMethod -Uri $connectUri -Headers $headers -Method Post -Body ($body | ConvertTo-Json -Depth 6)
        } catch {
          if ($_.Exception.Response.Content -match "WorkspaceAlreadyConnectedToGit") {
            Write-Host "Already connected"
          } else { throw $_ }
        }

        # Initialize (retry on UnknownError)
        $initUri = "https://api.fabric.microsoft.com/v1/workspaces/$workspaceId/git/initializeConnection"
        for ($i=1; $i -le 5; $i++) {
          try {
            Write-Host ("Attempt {0}: POST {1}" -f $i, $initUri)
            Invoke-RestMethod -Uri $initUri -Headers $headers -Method Post -Body "{}"
            break
          } catch {
            if ($_.Exception.Response.Content -match "UnknownError" -and $i -lt 5) {
              Start-Sleep -Seconds 15
            } else { throw $_ }
          }
        }

 

2 REPLIES 2
v-sgandrathi
Honored Contributor II

Hi @yazdanb,

Thank you for reaching out to the Microsoft Fabric Community.


Based on your description, the issue seems to occur because the initializeConnection API call is missing the required parameters and proper handling for long-running operations (LRO). In Fabric, this endpoint does not complete immediately; instead, it returns a 202 Accepted response with a Location header containing an operation URL. You need to poll this URL until the initialization is finished. If you send an empty JSON body ({}) or omit the initializationStrategy, the API may return an UnknownError or make the workspace look connected without being fully initialized, leading to the "WorkspaceGitConnectionNotInitialized" message.

To resolve this, update your API call to include the initializationStrategy parameter in the request body. For most automated deployments, use the following payload:

{ "initializationStrategy": "PreferRemote" }

 

Alternatively, you can use "PreferWorkspace" if you want your Fabric workspace content to take precedence over the repository. Once you submit this request, make sure to capture the Location URL from the response headers and keep polling that endpoint until the operation state is Succeeded. Skipping this step will leave the connection in a partial state and can cause the same circular issue you're experiencing.

Also, check that your service principal's Git credentials are correctly set up. You can do this by calling GET /git/myGitCredentials to verify the source is "ConfiguredConnection" and that the connectionId matches the one in your connect request. If it's not set up, you can update it using the PATCH endpoint as shown:

{ "source": "ConfiguredConnection", "connectionId": "<FABRIC_CONNECTION_ID>" }

 

Without this configuration, /git/connect may show success, but initialization can fail if credentials aren't linked. After successful initialization, check GET /git/status. If "requiredAction" is "UpdateFromGit", use POST /git/updateFromGit and poll until done. Make sure your Fabric workspace has capacity assigned and your service principal has Admin access to both the workspace and Azure DevOps repository for the Git APIs to work.

 

Git - Initialize Connection - REST API (Core) | Microsoft Learn
Git - Connect - REST API (Core) | Microsoft Learn

 

Thank you and regards,
Sahasra.

v-sgandrathi
Honored Contributor II

HI @yazdanb,

 

Just wanted to follow up and confirm that everything has been going well on this. Please let me know if thereโ€™s anything from our end.
Please feel free to reach out Microsoft fabric community forum.

 

Thank you.

Helpful resources

Announcements
Users online (11,584)