cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Databricks Query History API (REST API)

Constantine
Contributor III

I have setup authentication using this page https://docs.databricks.com/sql/api/authentication.html

and run

curl -n -X GET https://<databricks-instance>.cloud.databricks.com/api/2.0/sql/history/queries

To get history of all sql endpoint queries, but I want to get all queries for a particular day - say Jan 1st, 2021.

How do I do this? I don't see any examples in the documentation about this

1 ACCEPTED SOLUTION

Accepted Solutions

AmanSehgal
Honored Contributor III

Hi @John Constantine​ 

To the above GET request add following raw data.

{
 "filter_by": {
   "endpoint_ids": ["<endpoint_id_1", "<endpoint_id_2", ...... "<endpoint_id_N"],
   "query_start_time_range":{
       "start_time_ms" :1640995200000, 
       "end_time_ms" : 1641081599000
   }
 },
 "max_results": 999
}

 Here,

1640995200000 refers to Saturday, January 1, 2022 12:00:00 AM GMT+0

1641081599000 refers to Saturday, January 1, 2022 11:59:59 PM GMT+0

  

Refer to Query API 2.0 documentation for more filters.

View solution in original post

5 REPLIES 5

Kaniz_Fatma
Community Manager
Community Manager

Hi @ Constantine! My name is Kaniz, and I'm the technical moderator here. Great to meet you, and thanks for your question! Let's see if your peers in the community have an answer to your question first. Or else I will get back to you soon. Thanks.

AmanSehgal
Honored Contributor III

Hi @John Constantine​ 

To the above GET request add following raw data.

{
 "filter_by": {
   "endpoint_ids": ["<endpoint_id_1", "<endpoint_id_2", ...... "<endpoint_id_N"],
   "query_start_time_range":{
       "start_time_ms" :1640995200000, 
       "end_time_ms" : 1641081599000
   }
 },
 "max_results": 999
}

 Here,

1640995200000 refers to Saturday, January 1, 2022 12:00:00 AM GMT+0

1641081599000 refers to Saturday, January 1, 2022 11:59:59 PM GMT+0

  

Refer to Query API 2.0 documentation for more filters.

jose_gonzalez
Moderator
Moderator

Hi @John Constantine​ ,

Did @Aman Sehgal​ response helped you with your question? If it does, could you please mark it as best response.

MorpheusGoGo
New Contributor II

Are you sure this works?

payload = {
 "filter_by": {  
 },
 "max_results": 1
}
 
Returns 1 result.
 
payload = {
 "filter_by": {  
   "query_start_time_range":{
       "start_time_ms" :1640995200000,
       "end_time_ms" : 1641081599000
   }
 },
 "max_results": 1
}
 
{'error_code': 'MALFORMED_REQUEST', 'message': "Could not parse request object: Expected 'START_OBJECT' not 'VALUE_STRING'\n at [Source: (ByteArrayInputStream); line: 1, column: 15]\n at [Source: java.io.ByteArrayInputStream@5297a56c; line: 1, column: 15]"}
 

Cheryl
New Contributor II

I get the same error message - databricks documentation is not showing a working example

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!