SQL Execution API Code 400
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 06:32 PM
I am trying to execute the following command to test API but getting response 400
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 10:03 PM
@xavier20
You need to put bearer token in header, just like in this example:
https://docs.databricks.com/en/sql/admin/sql-execution-tutorial.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 09:07 AM
A 400 status code response indicates that the server was unable to process the request due to a client error, e.g., incorrect syntax, invalid parametersBased on the code you provided, it appears that you are trying to execute a SQL query against your Azure Databricks workspace using the Databricks SQL REST API. However, you are encountering a 400 error when you run the script.
A 400 error typically indicates that the server could not understand the request due to bad syntax or invalid arguments. Here are a few things you can check to troubleshoot this issue:
Check that the URL variable is set correctly:
Verify that the URL variable is set to the correct endpoint for your Databricks workspace. The URL should be in the format https://<databricks-instance>/api/2.0/sql/statements/.
Verify that the WAREHOUSE and AUTH_TOKEN variables are set correctly:
Make sure that the WAREHOUSE and AUTH_TOKEN variables are set to valid values for your Databricks workspace. You can verify these values in the Databricks workspace UI or by using the Databricks CLI.
Verify the validity of the SQL statement:
Make sure that the SQL statement you are trying to execute is valid. You can test the statement directly in the Databricks workspace using the SQL editor.
Check for typos or syntax errors:
Review your code for any typos or syntax errors that may be causing the issue. Make sure that all variables and values are spelled correctly and formatted properly.
If you are still encountering issues after reviewing these areas, it may be helpful to review the error message returned from the API call to get more information on the specific issue. You can do this using the response.content property of the requests.post() call, which will display the raw response content from the API endpoint.

