<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Service principal’s Microsoft Entra ID access token returns 400 when calling Databricks REST API in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/service-principal-s-microsoft-entra-id-access-token-returns-400/m-p/74706#M34782</link>
    <description>&lt;P&gt;Yes, I can see the access_token returned from the token api. The only return I get from the Databricks catalogs API is&amp;nbsp;&lt;SPAN&gt;&amp;lt;Response [400]&amp;gt;. The service principal is a member of an account group that is a member of workspace admin which inherits Can Manage on PAT. I tried explicitly granted the service principal Can Use token permissions but still get the same results.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Jun 2024 19:13:07 GMT</pubDate>
    <dc:creator>WTW-DBrat</dc:creator>
    <dc:date>2024-06-17T19:13:07Z</dc:date>
    <item>
      <title>Service principal’s Microsoft Entra ID access token returns 400 when calling Databricks REST API</title>
      <link>https://community.databricks.com/t5/data-engineering/service-principal-s-microsoft-entra-id-access-token-returns-400/m-p/74651#M34769</link>
      <description>&lt;P&gt;I'm using the following to call a&amp;nbsp;Databricks REST API. When I use a PAT for&amp;nbsp;&lt;SPAN&gt;access_token, everything works fine. When I use a&amp;nbsp;Microsoft Entra ID access token, the response returns 400. The service principal has access to the workspace and is part of the workspace admin group. The call to the token api is successful and returns a token. According to the &lt;A href="https://learn.microsoft.com/en-us/azure/databricks/dev-tools/service-prin-aad-token#--get-a-microsoft-entra-id-access-token-with-the-microsoft-identity-platform-rest-api" target="_self"&gt;documentation&lt;/A&gt;,&amp;nbsp;the&amp;nbsp;Microsoft Entra ID access token should work with the&amp;nbsp;Databricks REST API. What am I doing wrong?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
import json

tenant_id =  dbutils.secrets.get("IMDL_AKV", "tenant-id")
client_id =  dbutils.secrets.get("IMDL_AKV", "sp-id")
client_secret = dbutils.secrets.get("IMDL_AKV", "sp-secret")

url = f"https://login.microsoftonline.com/{tenant_id}/oauth2/token"
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
data = {
    'client_id': client_id,
    'grant_type': 'client_credentials',
    'scope': 'https://graph.microsoft.com/.default',
    'client_secret': client_secret
}

response = requests.post(url, headers=headers, data=data)
responseJson = json.loads(response.text)
access_token = response.json().get('access_token')

databricksURL = dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiUrl().getOrElse(None)
#print(access_token)

header = {'Authorization': 'Bearer {}'.format(access_token)}
endpoint = '/api/2.1/unity-catalog/catalogs/test_dev'
payload = json.dumps({  "isolation_mode": "ISOLATED"})

resp = requests.patch(
  databricksURL + endpoint,
  data=payload,
  headers=header
)

print(resp)
responseJson = json.loads(resp.text)
print(responseJson)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 15:07:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/service-principal-s-microsoft-entra-id-access-token-returns-400/m-p/74651#M34769</guid>
      <dc:creator>WTW-DBrat</dc:creator>
      <dc:date>2024-06-17T15:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Service principal’s Microsoft Entra ID access token returns 400 when calling Databricks REST API</title>
      <link>https://community.databricks.com/t5/data-engineering/service-principal-s-microsoft-entra-id-access-token-returns-400/m-p/74693#M34781</link>
      <description>&lt;P&gt;hello, Try to print the repose and see are you table to see the access_token in the payload else looks like access issue.&lt;BR /&gt;Try to go to the workspace setting and grant token access permission to the service principle.&lt;/P&gt;&lt;P&gt;Workspace &amp;gt; Setting&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jag_0-1718650459424.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/8768i6435209DE0943091/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="Jag_0-1718650459424.png" alt="Jag_0-1718650459424.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 18:55:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/service-principal-s-microsoft-entra-id-access-token-returns-400/m-p/74693#M34781</guid>
      <dc:creator>Jag</dc:creator>
      <dc:date>2024-06-17T18:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Service principal’s Microsoft Entra ID access token returns 400 when calling Databricks REST API</title>
      <link>https://community.databricks.com/t5/data-engineering/service-principal-s-microsoft-entra-id-access-token-returns-400/m-p/74706#M34782</link>
      <description>&lt;P&gt;Yes, I can see the access_token returned from the token api. The only return I get from the Databricks catalogs API is&amp;nbsp;&lt;SPAN&gt;&amp;lt;Response [400]&amp;gt;. The service principal is a member of an account group that is a member of workspace admin which inherits Can Manage on PAT. I tried explicitly granted the service principal Can Use token permissions but still get the same results.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 19:13:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/service-principal-s-microsoft-entra-id-access-token-returns-400/m-p/74706#M34782</guid>
      <dc:creator>WTW-DBrat</dc:creator>
      <dc:date>2024-06-17T19:13:07Z</dc:date>
    </item>
  </channel>
</rss>

