Thanks for the question and using MS Q&A platform.
- Check the expiration time of the access token you are using. If it has expired, you will need to obtain a new access token by following the AAD authentication process.
- Check if the AAD application has the correct permissions to access the Synapse workspace. You can do this by going to the AAD application's "API permissions" and verifying that it has the necessary permissions for the Synapse workspace.
- Ensure that the AAD application has Synapse roles are Workspace Admin, SQL Admin, and Spark Admin.
- Check AAD application has the Contributor role assigned to it in the Azure portal under Synapse Workspace
- Ensure that the AAD application has the necessary SQL permissions assigned to it.
Verify that you are using the correct access token when making the API call. You can use the Azure AD v2.0 endpoint to acquire the access token.
$tenantId = "your-tenant-id"
$clientId = "your-client-id"
$clientSecret = "your-client-secret"
$resource = "https://dev.azuresynapse.net"
$tokenEndpoint = "https://login.microsoftonline.com/$tenantId/oauth2/token"
$body = @{
grant_type = "client_credentials"
client_id = $clientId
client_secret = $clientSecret
resource = $resource
}
$accessTokenResponse = Invoke-RestMethod -Method Post -Uri $tokenEndpoint -Body $body
$accessToken = $accessTokenResponse.access_token
Make sure that the access token is included in the Authorization header of your API request. The header should be in the format "Bearer {access-token}".
$endpoint = "https://your-workspace.dev.azuresynapse.net/queryPipelineRuns?api-version=2020-12-01"
$headers = @{
"Authorization" = "Bearer $accessToken"
}
$response = Invoke-RestMethod -Method Post -Uri $endpoint -Headers $headers
I hope this helps! please do Let us know if you have any further questions.