Search code examples
powershellpowershell-2.0powershell-3.0powershell-4.0azure-powershell

Connect Azure Data Catalog REST API using powershell


i want to connect to Azure Data Catalog RestAPI using power shell script and below is my script which failed to run.

Get an Access Token with ADAL

$authContext = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext ("{0}" -f $login)

$authenticationResult = $authContext.AcquireToken($ResourceId, $ClientId, $redirectUri, $PromptBehavior);

($token = $authenticationResult.AccessToken) | Out-File $accessToken

$authContext.AcquireToken($ResourceId, $ClientId, $redirectUri, $PromptBehavior)


$headers = @{ 

    "Authorization" = ("Bearer {0}" -f $token);

}

$url = "https://api.azuredatacatalog.com/catalogs/DefaultCatalog/search/search?searchTerms=name:=Orders&count=10&api-version=2016-03-30"

$response = Invoke-RestMethod -Method GET -Uri $url -Headers $headers 

I am getting below error message

Invoke-RestMethod : 401 - Unauthorized: Access is denied due to invalid credentials. Server Error

401 - Unauthorized: Access is denied due to invalid credentials. You do not have permission to view this directory or page using the credentials that you supplied.

At line:1 char:13 + $response = Invoke-RestMethod -Method GET -Uri $url -Headers $headers + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Please help me in resolving the issue


Solution

  • You might need to grant your application access to the Azure Data Catalog via Azure AD.

    enter image description here

    Do note that this may require Administrator Approval to complete.