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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
amaaiia
Super User
Super User

Get workspace components git status through API call

Hi,

I'm trying to get workspace components git status calling GET https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/git/status (https://learn.microsoft.com/es-es/rest/api/fabric/core/git/get-status).

 

I use de "Try it" tab in the official page, and using my user token, it works. However, I need it to do with service principal authentication. Doc says Workspace.GitUpdate.All is enough: 

amaaiia_0-1758786737190.png


I've added this API permission to my registered APP. 

 

However, I call the API and I get a 400 bad request error: 

amaaiia_1-1758786905434.png

If I change the token and I set my personal account token, it works. The issue is happening when I put registered APP token. 

 

I get the token with: 

{ "method": "POST", "headers": { "Content-Type": "application/x-www-form-urlencoded" }, "body": "grant_type=client_credentials&client_id=<client_id>&client_secret=<client_secret>&scope=  https://analysis.windows.net/powerbi/api/.default " } 

 

I've used this token also for other API calls such us:  

https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/{element_type}
And it works, so I gess the token is correct for the scope of Fabric. I don't know why I'm getting a 400 bad request response.
 
Thanks.

 

 

10 REPLIES 10
Srisakthi
Super User
Super User

Hi @amaaiia ,

 

I have used the below code and im able to get the result with Service Principal.

function GetSecureTokenForServicePrincipal() {
$secureServicePrincipalSecret = ConvertTo-SecureString -String $client_secret -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $client_id, $secureServicePrincipalSecret

#Login to Azure using service principal
Connect-AzAccount -ServicePrincipal -TenantId $tenant_id -Subscription 'xxx-yyyy' -Credential $credential | Out-Null

# Get authentication
$secureFabricToken = (Get-AzAccessToken -AsSecureString -ResourceUrl $global:resourceUrl).Token

return $secureFabricToken
}
function ConvertSecureStringToPlainText($secureString) {
$ssPtr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($secureString)
try {
$plainText = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($ssPtr)
} finally {
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ssPtr)
}
return $plainText
}

$secureFabricToken = GetSecureTokenForServicePrincipal
$fabricToken = ConvertSecureStringToPlainText($secureFabricToken)

$global:baseUrl = "https://api.fabric.microsoft.com/v1"
$global:resourceUrl = "https://api.fabric.microsoft.com"

$global:fabricHeaders = @{
'Content-Type' = "application/json"
'Authorization' = "Bearer $fabricToken"
}
$gitStatusUrl = "{0}/workspaces/{1}/git/status" -f $global:baseUrl, $workspace.Id
$gitStatusResponse = Invoke-RestMethod -Headers $global:fabricHeaders -Uri $gitStatusUrl -Method GET

 

Note: Service Principal is not supported for warehouse git sync. other items are getting sync from git to workspace except warehouse.

 

Regards,

Sri

KevinChant
Super User
Super User

I recommend testing this outside of your pipeline with something like Postman. Is this for CI/CD deployments?

v-sdhruv
Community Support
Community Support

Hi @amaaiia ,

I hope you were successfully able to raise the support ticket.
If you have any issues, please let us know.
Thank You

tayloramy
Community Champion
Community Champion

Hi @amaaiia

 

Does the sersvicce principal have contributor or higher on the workspaces? These permissions are different from the delegated permissions in my experience. 

 

If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution. 

Contributor role on the workspace

Hi @amaaiia

 

Can you show me the exact POST request that you're sending? A 400 error usually means that your request is incorrect. Microsoft's APIs are particularly picky when it comes to the parameters and body.  

 

If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution. 

The POST request should be ok because if I change the Bearer token with a token of my personal account, I get 200 OK:

amaaiia_4-1759158246332.png

 

If I use service principal token, then I get 400:

amaaiia_3-1759158193676.png

 

But the POST request is the same.

@amaaiia Thanks for the info, so something is up with the service principal. 

 

How are you generating the bearer token? 

Can toy also confirm what delegated permissions the service principal has? 
Here's my function for generating the bearer token using the MSAL library

def get_access_token():
    app = ConfidentialClientApplication(
        CLIENT_ID,
        authority=AUTHORITY,
        client_credential=CLIENT_SECRET,
    )
    result = app.acquire_token_for_client(scopes=SCOPE)
    
    if 'access_token' in result:
        return result['access_token']
    else:
        error = result.get('error', 'No error information')
        error_description = result.get('error_description', 'No description')
        raise Exception(f"Could not obtain access token. Error: {error}. Description: {error_description}")

If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution. 

I get the token with: https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token

{ "method": "POST", "headers": { "Content-Type": "application/x-www-form-urlencoded" }, "body": "grant_type=client_credentials&client_id=<client_id>&client_secret=<client_secret>&scope=  https://analysis.windows.net/powerbi/api/.default " } 

 

And it works because I'm using it for other Fabric API calls such us: https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/{element_type}

 

These are API permissions, doc says GitUpdate is enough:

amaaiia_0-1759233244584.png

 

Hi @amaaiia

 

It looks like you're doing everything right. I'd recommend opening a ticket with Microsoft at this point. 

 

If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution.  

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Fabric Update Carousel

Fabric Monthly Update - September 2025

Check out the September 2025 Fabric update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.