Forum Discussion
Get workspace components git status through API call
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