<?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 Query example for databricks Query History API in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/query-example-for-databricks-query-history-api/m-p/64834#M32675</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to get query history data from my SQL warehouse.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Following previous examples is not working.&amp;nbsp;&lt;/P&gt;&lt;P&gt;databricks_workspace_url = "xxx"&lt;BR /&gt;token = "xxx"&lt;BR /&gt;start_time = 1707091200&lt;BR /&gt;end_time = 1707174000&lt;/P&gt;&lt;P&gt;api_endpoint = f"{databricks_workspace_url}/api/2.0/sql/history/queries"&lt;/P&gt;&lt;P&gt;headers = {&lt;BR /&gt;"Authorization": f"Bearer {token}",&lt;BR /&gt;"Content-Type": "application/json"&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;params={&lt;BR /&gt;"include_metrics": "true",&lt;BR /&gt;"warehouse_ids" : ['xxx'],&lt;BR /&gt;"filter_by": {&lt;BR /&gt;"query_start_time_range": {&lt;BR /&gt;"end_time_ms": end_time,&lt;BR /&gt;"start_time_ms": start_time&lt;BR /&gt;},&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;response = requests.get(api_endpoint, headers=headers, params=params)&lt;/P&gt;&lt;P&gt;I get the following error -&lt;/P&gt;&lt;PRE&gt;Error: 400 - {"error_code":"MALFORMED_REQUEST","message":"Could not parse request object: Expected 'START_OBJECT' not 'VALUE_STRING'\n at [Source: (ByteArrayInputStream); line: 1, column: 75]\n at [Source: java.io.ByteArrayInputStream@6efba358; line: 1, column: 75]"}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Mar 2024 18:06:27 GMT</pubDate>
    <dc:creator>Cheryl</dc:creator>
    <dc:date>2024-03-27T18:06:27Z</dc:date>
    <item>
      <title>Query example for databricks Query History API</title>
      <link>https://community.databricks.com/t5/data-engineering/query-example-for-databricks-query-history-api/m-p/64834#M32675</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to get query history data from my SQL warehouse.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Following previous examples is not working.&amp;nbsp;&lt;/P&gt;&lt;P&gt;databricks_workspace_url = "xxx"&lt;BR /&gt;token = "xxx"&lt;BR /&gt;start_time = 1707091200&lt;BR /&gt;end_time = 1707174000&lt;/P&gt;&lt;P&gt;api_endpoint = f"{databricks_workspace_url}/api/2.0/sql/history/queries"&lt;/P&gt;&lt;P&gt;headers = {&lt;BR /&gt;"Authorization": f"Bearer {token}",&lt;BR /&gt;"Content-Type": "application/json"&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;params={&lt;BR /&gt;"include_metrics": "true",&lt;BR /&gt;"warehouse_ids" : ['xxx'],&lt;BR /&gt;"filter_by": {&lt;BR /&gt;"query_start_time_range": {&lt;BR /&gt;"end_time_ms": end_time,&lt;BR /&gt;"start_time_ms": start_time&lt;BR /&gt;},&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;response = requests.get(api_endpoint, headers=headers, params=params)&lt;/P&gt;&lt;P&gt;I get the following error -&lt;/P&gt;&lt;PRE&gt;Error: 400 - {"error_code":"MALFORMED_REQUEST","message":"Could not parse request object: Expected 'START_OBJECT' not 'VALUE_STRING'\n at [Source: (ByteArrayInputStream); line: 1, column: 75]\n at [Source: java.io.ByteArrayInputStream@6efba358; line: 1, column: 75]"}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 18:06:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/query-example-for-databricks-query-history-api/m-p/64834#M32675</guid>
      <dc:creator>Cheryl</dc:creator>
      <dc:date>2024-03-27T18:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: Query example for databricks Query History API</title>
      <link>https://community.databricks.com/t5/data-engineering/query-example-for-databricks-query-history-api/m-p/64845#M32683</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/102926"&gt;@Cheryl&lt;/a&gt;&amp;nbsp;- you can use&amp;nbsp;&lt;STRONG style="font-family: inherit; color: #183139;"&gt;query_start_time=2023-01-01T00:00:00Z&amp;nbsp;&lt;/STRONG&gt; as a parameter to filter for the time frame. available filter criteria are given below -&amp;nbsp;&lt;A href="https://docs.databricks.com/api/workspace/queryhistory/list#filter_by-query_start_time_range" target="_blank"&gt;https://docs.databricks.com/api/workspace/queryhistory/list#filter_by-query_start_time_range&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 27 Mar 2024 20:02:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/query-example-for-databricks-query-history-api/m-p/64845#M32683</guid>
      <dc:creator>shan_chandra</dc:creator>
      <dc:date>2024-03-27T20:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Query example for databricks Query History API</title>
      <link>https://community.databricks.com/t5/data-engineering/query-example-for-databricks-query-history-api/m-p/64855#M32685</link>
      <description>&lt;P&gt;do you mean like this? if so, I'm getting the same error unfortunately.&lt;/P&gt;&lt;P&gt;query_start_time='2024-03-01T00:00:00Z'&lt;BR /&gt;query_end_time='2024-03-02T00:00:00Z'&lt;/P&gt;&lt;P&gt;params={&lt;BR /&gt;"include_metrics": "true",&lt;BR /&gt;"warehouse_ids" : ['xxx'],&lt;BR /&gt;"filter_by": {&lt;BR /&gt;"query_start_time_range": {&lt;BR /&gt;"end_time_ms": query_end_time,&lt;BR /&gt;"start_time_ms": query_start_time&lt;BR /&gt;},&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 21:37:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/query-example-for-databricks-query-history-api/m-p/64855#M32685</guid>
      <dc:creator>Cheryl</dc:creator>
      <dc:date>2024-03-27T21:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Query example for databricks Query History API</title>
      <link>https://community.databricks.com/t5/data-engineering/query-example-for-databricks-query-history-api/m-p/64923#M32704</link>
      <description>&lt;P&gt;Cheryl - Please find the below script to retrieve the issue.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;import requests
import json

workspace_url = 'XXXX'
uri = f"https://{workspace_url}/api/2.0/sql/history/queries"
print(uri)
headers_auth = {"Authorization": "Bearer XXXX"}


start_ts_ms = 1711577103226
end_ts_ms = 1711577179912

request_string = {
    "filter_by": {
        "query_start_time_range": {
            "end_time_ms": end_ts_ms,
            "start_time_ms": start_ts_ms
        },
        "statuses": [
            "FINISHED", "CANCELED"
        ],
        "warehouse_ids": "XXXX"
    },
    "include_metrics": "true",
    "max_results": "1000"
}

v = json.dumps(request_string)

endp_resp = requests.get(uri, data=v, headers=headers_auth).json()
beautified_resp = json.dumps(endp_resp, indent=4)
print(beautified_resp)

&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 15:32:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/query-example-for-databricks-query-history-api/m-p/64923#M32704</guid>
      <dc:creator>shan_chandra</dc:creator>
      <dc:date>2024-03-28T15:32:34Z</dc:date>
    </item>
  </channel>
</rss>

