0

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

2
  • Are you using a Service Principal, Application, or an AD user to connect? Commented Jun 14, 2018 at 11:36
  • Below are the details used to connect. # Output Token and Response from AAD Graph API $accessToken = ".\Token.txt" $output = ".\Output.json" # Application and Tenant Configuration $clientId = "****.****.****.****.****" $resourceId = "api.azuredatacatalog.com" $redirectUri = New-Object system.uri("login.live.com/oauth20_desktop.srf") $login = "login.windows.net/common/oauth2/authorize"; Commented Jun 14, 2018 at 12:45

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, Thanks for the response. We have permissions to access azure data catalog and still we face the same issue.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.