Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to: ✅ Azure Data Explorer
This article describes how to use a subset of the T-SQL language to send T-SQL queries via the REST API.
Request structure
To send T-SQL queries to the API, create a POST request with the following components.
To copy your URI, in the Azure portal, go to your cluster's overview page, and then select the URI.
https://<your_cluster>.kusto.chinacloudapi.cn/MyDatabase? web=0&query=KustoLogs+%7c+where+Timestamp+>+ago({Period})+%7c+count&Period=1h
Replace <your_cluster> with your Azure Data Explorer cluster name.
Request URL: The URL should be formatted as
https://<cluster_uri>/v1/rest/query, where<cluster_uri>is the URI of your cluster or database containing the table you want to query.Headers: Set the following headers. Replace
<cluster_uri>and<bearer_token>with your specific cluster or database URI and bearer token values.Accept:application/json Content-Type:application/json; charset=utf-8 Host:<cluster_uri> Authorization: Bearer <bearer_token>Body: Set the
cslproperty to the text of your T-SQL query, and the client request propertyquery_languagetosql.{ "csl": "<t_sql_query>", "properties": { "Options": { "query_language": "sql" } } }
Example
The following example shows a request body with a T-SQL query in the csl field and the query_language client request property set to sql.
{
"db": "MyDatabase",
"csl": "SELECT top(10) * FROM MyTable",
"properties": {
"Options": {
"query_language": "sql"
}
}
}
The response is in a format similar to the following.
{
"Tables": [
{
"TableName": "Table_0",
"Columns": [
{
"ColumnName": "rf_id",
"DataType": "String",
"ColumnType": "string"
},
...
],
"Rows": [
[
"b9b84d3451b4d3183d0640df455399a9",
...
],
...
]
}
]
}
Related content
- Learn more about T-SQL limitations
- See the REST API overview