Skip to main content

Custom data query API

Last updated 10/03/2026

After you generate a query token, you can query project data by calling the custom query API. For how to make calls, see the Open API documentation.

1. SQL query​

1. SQL query​

Endpoint URL

/querySql?token=xxx&format=json&timeoutSeconds=10&sql=select "#country","#province","#city" from v_event_102 where "$part_date"='2018-10-01' limit 200

Request method

POST

Content-Type

application/x-www-form-urlencoded

Request query parameters

Parameter nameExample valueParameter typeRequiredDescription
tokenxxxStringYesQuery key
sqlselect "#country","#province","#city" from v_event_102 where "$part_date"='2018-10-01' limit 200StringYesSQL statement to run
format

json

StringNo

Row data format, json by default

(json,csv,csv_header,tsv,tsv_header,json_object)

timeoutSeconds10IntegerNoRequest timeout. The query task is canceled when it times out

Success response example

Results are separated by line, and each line uses the format specified when the query statement was run.

1. Results in json format

When the format is json, the first line contains the status value and data metadata in the following format:

{
"data": {
"headers": [
"#country",
"#province",
"#city"
]
},
"return_code": 0,
"return_message": "success"
}
$$Parameter nameExample valueParameter typeDescription
return_code0IntegerReturn code
return_messagesuccessStringReturn message
data-ObjectReturned result
data.headers["#country", "#province", "#city"]ListFirst line

If the query result isn't empty, data lines follow the first line

["China","Gansu","Lanzhou"]
["China","Beijing","Beijing"]
["China","Guangdong","Guangzhou"]
["China","Gansu","Lanzhou"]

2. Results in other formats

When the format is csv_header or tsv_header, the first line contains the column names (csv):

"#country","#province","#city"

Each following line is a list containing the returned results (csv)

"China","Gansu","Lanzhou"
"China","Beijing","Beijing"
"China","Guangdong","Guangzhou"
"China","Gansu","Lanzhou"

3. When the format is csv or tsv

The results contain no column names, only data.

curl example

curl -X POST 'http://ta2:8992/querySql?token=YOUR_TOKEN' --header 'Content-Type: application/x-www-form-urlencoded' -d 'sql=select+%22%23country%22%2c%22%23province%22%2c%22%23city%22+from+v_event_102+where+%22%24part_date%22%3d%272018-10-01%27+limit+200&format=json&timeoutSeconds=10'

2. SQL paginated query​

The SQL paginated query API has two related methods. The first runs the query statement and, when it finishes, returns the result's meta information and pagination information. The second downloads paginated result data.

2. Run a query statement​

Endpoint URL

/open/execute-sql?token=xxx&sql=select * from v_user_0 limit 11000&pageSize=10000&format=json&timeoutSeconds=10

Request method

POST

Content-Type

application/x-www-form-urlencoded

Request query parameters

Parameter nameExample valueParameter typeRequiredDescription
tokenxxxStringYesQuery key
sqlselect * from v_user_0 limit 11000StringYesSQL statement to run
formatjsonStringNoRow data format (json,csv,tsv,json_object), json by default
pageSize10000IntegerNoRows per page, minimum 1000, 10000 by default
timeoutSeconds10IntegerNoRequest timeout. The query task is canceled when it times out

Success response example

{
"data": {
"headers": [
"#user_id",
"#account_id",
"#distinct_id",
"#active_time",
"#reg_time",
"#user_operation",
"#server_time",
"#is_delete",
"#update_time",
"user_level",
"coin_num",
"register_time",
"diamond_num",
"first_recharge_time"
],
"pageCount": 2,
"pageSize": 10000,
"rowCount": 11000,
"taskId": "119a3a37411f3000"
},
"return_code": 0,
"return_message": "success"
}
$$Parameter nameExample valueParameter typeDescription
return_code0IntegerReturn code
return_messagesuccessStringReturn message
data-ObjectReturned data
data.pageCount2IntegerTotal pages of result data
data.pageSize10000IntegerRows per page
data.rowCount11000IntegerTotal rows of result data
data.header["#user_id"]ListField list of the first line
data.taskId119a3a37411f3000StringTask ID

Error response example

{
"return_code": -1008,
"return_message": "Parameter (token) is empty"
}
Parameter nameExample valueParameter typeDescription
return_code-1008IntegerReturn code
return_messageParameter (token) is emptyStringReturn message

curl example

curl -X POST 'http://ta2:8992/open/execute-sql?token=YOUR_TOKEN' --header 'Content-Type: application/x-www-form-urlencoded' -d 'sql=select%20*%20from%20v_user_0%20limit%2011000&pageSize=10000&format=json&timeoutSeconds=10'

3. Download paginated result data​

Endpoint URL

/open/sql-result-page?token=xxx&taskId=119a3a37411f3000&pageId=0

Request method

GET

Content-Type

application/json

Request query parameters

Parameter nameExample valueParameter typeRequiredDescription
tokenxxxStringYesQuery key

taskId

119a3a37411f3000StringYesThe taskId field returned by the query execution API
pageId0IntegerNoValue range: [0, pageCount-1], 0 by default

2.1 Results are separated by line, and each line uses the format specified when the query statement was run

[9324080,"c21756080","c40404080","2019-12-15 16:09:07.000","2019-12-15 16:09:07.000","user_set","2019-12-15 16:22:13.000",false,"2020-06-03 13:10:02.494",6,40000,"2019-12-15 16:09:07.000",0,null]
[9328294,"q21765894","q40422294","2019-12-15 16:19:49.000","2019-12-15 16:19:49.000","user_set","2019-12-15 16:42:18.000",false,"2020-06-03 13:10:02.494",17,642440,"2019-12-15 16:19:49.000",112,"2019-12-15 16:26:13.000"]
[9335719,"t21783319","t40454719","2019-12-15 16:29:45.000","2019-12-15 16:29:45.000","user_set","2019-12-15 16:42:18.000",false,"2020-06-03 13:10:02.494",6,70000,"2019-12-15 16:29:45.000",0,null]

2.2 When format is set to json_object in /open/execute-sql, results are returned in the following format:

{"app_version": "1.1", "channel": "Baidu", "server_time": "2020-06-03 13:10:02.494", "distinct_id": "c40404080"}
{"app_version": "1.1", "channel": "Baidu", "server_time": "2020-06-03 13:10:02.494", "distinct_id": "q21765894"}
{"app_version": "1.1", "channel": "Baidu", "server_time": "2020-06-03 13:10:02.494", "distinct_id": "t21783319"}

Error response example

{
"return_code": -1,
"return_message": "The task is running"
}
Parameter nameExample valueParameter typeDescription
return_code-1IntegerReturn code
return_messageThe task is runningThe task is runningStringReturn message

curl example

curl -X GET 'http://ta2:8992/open/sql-result-page?token=YOUR_TOKEN&taskId=119a3a37411f3000&pageId=1'

3. SQL asynchronous query API​

The SQL asynchronous query API has four related methods.

  • Submit a query statement and return the query task ID;
  • Check the execution status of a query task.
  • Get the result data of a query task.
  • Cancel an unfinished task.

4. Run a query statement​

Endpoint URL

/open/submit-sql?token=xxx&format=json&sql=select * from v_user_0 limit 11000

Request method

POST

Content-Type

application/json

Request query parameters

Parameter nameExample valueParameter typeRequiredDescription
tokenxxxStringYesQuery key

sql

select * from v_user_0 limit 11000StringYesSQL statement to run
formatjsonStringNoRow data format (json,csv,tsv,json_object), json by default
pageSize1000IntegerNoRows per page, minimum 1000, no pagination by default

Success response example

{
"data": {
"taskId": "119a3a37411f3000"
},
"return_code": 0,
"return_message": "success"
}
$$Parameter nameExample valueParameter typeDescription
data-ObjectReturned result
data.taskId119a3a37411f3000StringTask ID
return_code0IntegerReturn code
return_messagesuccessStringReturn message

Error response example

{
"return_code": -1008,
"return_message": "Parameter (token) is empty"
}
Parameter nameExample valueParameter typeDescription
return_code-1008IntegerReturn code
return_messageParameter (token) is emptyStringReturn message

curl example

curl -X POST 'http://ta2:8992/open/submit-sql?token=YOUR_TOKEN' --header 'Content-Type: application/x-www-form-urlencoded' -d 'sql=select%20*%20from%20v_user_0%20limit%2011000&format=json'

5. Check the execution status of a query task​

Endpoint URL

/open/sql-task-info?token=xxx&taskId=119a3a37411f3000

Request method

GET

Content-Type

application/json

Request query parameters

Parameter nameExample valueParameter typeRequiredDescription
tokenxxxStringYesQuery key
taskId119a3a37411f3000StringYesThe taskId in the result returned by the query execution API

Success response example

{
"data": {
"taskId": "119a3a37411f3000",
"status": "FINISHED",
"progress": 100,
"resultStat": {
"rowCount": 11000,
"pageCount": 1,
"headers": [
"#user_id",
"#account_id",
"#distinct_id",
"#active_time",
"#reg_time",
"#user_operation",
"#server_time",
"#is_delete",
"#update_time",
"user_level",
"coin_num",
"register_time",
"diamond_num",
"first_recharge_time"
]
}
},
"return_code": 0,
"return_message": "success"
}
$$Parameter nameExample valueParameter typeDescription
return_code0IntegerReturn code
return_messagesuccessStringReturn message
data-ObjectReturned result
data.taskId119a3a37411f3000StringID of the query task, used to download paginated result data later
data.statusFINISHEDStringTask status (RUNNING, FINISHED, FAILED)
data.progress100IntegerQuery progress (a value between 0 and 100 while RUNNING)
data.resultStat-ObjectResult information, returned when the status is FINISHED
data.resultStat.headers["#user_id"]ListList of column names
data.resultStat.rowCount11000IntegerTotal rows
data.resultStat.pageCount1IntegerTotal pages

Error response example

{
"return_code": -1008,
"return_message": "Parameter (token) is empty"
}
Parameter nameExample valueParameter typeDescription
return_code-1008IntegerReturn code
return_messageParameter (token) is emptyStringReturn message

curl example

curl -X GET 'http://ta2:8992/open/sql-task-info?token=YOUR_TOKEN&taskId=119a3a37411f3000'

6. Download paginated result data​

Endpoint URL

/open/sql-result-page?token=xxx&taskId=119a3a37411f3000

Request method

GET

Content-Type

application/json

Request query parameters

Parameter nameExample valueParameter typeRequiredDescription
tokenxxxStringYesQuery key
taskId119a3a37411f3000StringYesThe taskId in the result returned by the query execution API
pageId0IntegerNoValue range: [0, pageCount-1], 0 by default

Results are separated by line, and each line uses the format specified when the query statement was run

[9324080,"c21756080","c40404080","2019-12-15 16:09:07.000","2019-12-15 16:09:07.000","user_set","2019-12-15 16:22:13.000",false,"2020-06-03 13:10:02.494",6,40000,"2019-12-15 16:09:07.000",0,null]
[9328294,"q21765894","q40422294","2019-12-15 16:19:49.000","2019-12-15 16:19:49.000","user_set","2019-12-15 16:42:18.000",false,"2020-06-03 13:10:02.494",17,642440,"2019-12-15 16:19:49.000",112,"2019-12-15 16:26:13.000"]
[9335719,"t21783319","t40454719","2019-12-15 16:29:45.000","2019-12-15 16:29:45.000","user_set","2019-12-15 16:42:18.000",false,"2020-06-03 13:10:02.494",6,70000,"2019-12-15 16:29:45.000",0,null]

Error response example

{
"return_code": -1008,
"return_message": "Parameter (token) is empty"
}
Parameter nameExample valueParameter typeDescription
return_code-1008IntegerReturn code
return_messageParameter (token) is emptyStringReturn message

curl example

curl -X GET 'http://ta2:8992/open/sql-result-page?token=YOUR_TOKEN&taskId=119a3a37411f3000'

7. Cancel an unfinished task​

Endpoint URL

/open/cancel-sql-task?token=xxx&taskId=119a3a37411f3000

Request method

POST

Content-Type

application/json

Request query parameters

Parameter nameExample valueParameter typeRequiredDescription
tokenxxxStringYesQuery key
taskId119a3a37411f3000StringYesThe taskId in the result returned by the query execution API

Success response example

{
"return_code": 0,
"return_message": "success"
}

Error response example

{
"return_code": -1008,
"return_message": "Parameter (token) is empty"
}
Parameter nameExample valueParameter typeDescription
return_code-1008IntegerReturn code
return_messageParameter (token) is emptyStringReturn message

curl example

curl -X POST 'http://ta2:8992/open/cancel-sql-task?token=YOUR_TOKEN&taskId=119a3a37411f3000'
Was this page helpful?