This is the SQL Evaluation API resource documentation. If you face any issues or have any requests, please contact support.
The SQL evaluation API provides endpoints for executing SQL queries against various database servers. It can be accessed using an API key-based authentication and authorization process.
You must register your web application in order to receive a client-specific client-secret that must be provided while communicating with the API.
Currently, there is a limit on the number of:
Register your own client and generate an API key here.
The client authentication is done using your unique client-secret API key which you generated. You need to pass this client secret in the request header with the key as client-secret and value as the Client Secret Key which you receive after registering your client (as described above).
You have to pass the following two mandatory headers:
https://api.hackerearth.com/sql-evaluation/v1/submissions/
{
"dbType": "MYSQL",
"problemId": "5dcb19fbd3f1481a9f79a0ad04bbea8b",
"sourceCode": "select count(*) from RetailOutlet;",
"timeLimit": 10,
"requestContext": "{'customId': 213121}",
"callbackUrl": "https://client.com/callback/"
}
{
"requestId": "e885e329-beb8-407d-a2a6-d31c7c919407",
"requestStatus": {
"code": "REQUEST_COMPLETED",
"message": "Your request has been completed successfully"
},
"result": {
"status": "AC",
"output": "https://he-s3.s3.ap-southeast-1.amazonaws.com/media/userdata/AnonymousUser/code/a7e4f31",
"timeUsed": 0.000794172286987305,
"stderr": null
},
"requestContext": "{'customId': 213121}",
"getStatusUrl": "https://api.hackerearth.com/sql-evaluation/v1/submissions/request/e885e329-beb8-407d-a2a6-d31c7c919407/",
"errors": {}
}
This is the payload that is returned as an immediate response for the API call:
{
"requestId": "e885e329-beb8-407d-a2a6-d31c7c919406",
"requestStatus": {
"code": "REQUEST_INITIATED",
"message": "Your request has been recorded and initiated"
},
"result": {
"status": "NA",
"output": null,
"timeUsed": null,
"stderr": null
},
"requestContext": "{'customId': 213121}",
"getStatusUrl": "https://api.hackerearth.com/sql-evaluation/v1/submissions/request/e885e329-beb8-407d-a2a6-d31c7c919407/",
"errors": {}
}
Status | Explanation |
AC | Accepted. The SQL code executed successfully. |
TLE | Time Limit Exceeded. The execution of the SQL code took more time than the passed time limit. |
RE | Runtime error occurred during the execution of the SQL code. |
https://api.hackerearth.com/sql-evaluation/v1/submissions/request/{requestId}/
The requestId
parameter is the value of the requestId
attribute that you receive in the response while submitting the POST request for SQL evaluation. This requestId attribute uniquely identifies every SQL evaluation request made by the client.
Like in the POST request above, it requires you to pass client-secret
in the header for authentication purposes.
The response format of this API is the same as that of the Submit Evaluation API.
In case of an error with the API requests, the response contains the details of the error as follows:
{
"error": {
"type": "badData",
"message": "Invalid request data provided.",
"details": {
"dbType": [
"This field is required."
]
}
}
}
{
"error": {
"type": "quotaExceededError",
"message": "API usage quota exceeded.",
"details": {
"quota": 73000000,
"currentCount": 120189
}
}
}
{
"error": {
"type": "authFailed",
"message": "Authentication Failed.",
"details": {
"reason": "No client-secret provided."
}
}
}
{
"error": {
"type": "authFailed",
"message": "Authentication Failed.",
"details": {
"reason": "Client Secret contains invalid characters."
}
}
}
{
"error": {
"type": "authFailed",
"message": "Authentication Failed.",
"details": {
"reason": "Client Secret does not match."
}
}
}
{
"error": {
"type": "notFound",
"message": "Entity not found.",
"details": {}
}
}
{
"error": {
"type": "processingError",
"message": "Processing Error occurred. Please try again!",
"details": {}
}
}
import json
import requests
SQL_EVALUATION_URL = 'https://api.hackerearth.com/sql-evaluation/v1/submissions/'
CLIENT_SECRET = 'cf078d6f6fa13508b9d374545f48fe142b43b64e'
def execute_sql(db_type, source_code, request_context):
problem_id = '5dcb19fbdd31481a9f20a0ad04bbea8b'
time_limit = 5
callback_url = "https://client.com/callback/"
data = {
'dbType': db_type,
'problemId': problem_id,
'sourceCode': source_code,
'timeLimit': time_limit,
'requestContext': request_context,
'callbackUrl' : callback_url,
}
headers = {"client-secret": CLIENT_SECRET}
response = requests.post(SQL_EVALUATION_URL, json=data, headers=headers)
dict = json.loads(response.text)
return dict
response_dict = execute_sql(db_type="MYSQL", source_code="select count(*) from RetailOutlet;", request_context="{'customId': 213121}")
curl -X POST \
https://api.hackerearth.com/sql-evaluation/v1/submissions/ \
-H 'cache-control: no-cache' \
-H 'client-secret: cf078d6f6fa13508b9d374545f48fe142b43b64e' \
-H 'content-type: application/json' \
-d '{"dbType": "MYSQL", "problemId": "5dcb19fbdd31481a9f20a0ad04bbea8b",
"sourceCode": "select count(*) from RetailOutlet;", "timeLimit": 5,
"requestContext": "{'customId': 213121}", "callbackUrl": "https://client.com/execute/result/"}'
import json
import requests
GET_STATUS_URL = u'https://api.hackerearth.com/sql-evaluation/v1/submissions/request/cf81e6d9-c6b9-4dcb-a3af-90b0a138996b/'
CLIENT_SECRET = 'cf025d6f6fa13560b9d543745f48fe562b43b46e'
def get_sql_eval_status():
headers = {"client-secret": CLIENT_SECRET}
resp = requests.get(GET_STATUS_URL, headers=headers)
dict = json.loads(resp.text)
return dict
response_dict = get_sql_eval_status()
curl -X GET \
https://api.hackerearth.com/sql-evaluation/v1/submissions/request/cf81e6d9-c6b9-4dcb-a3af-90b0a138996b/ \
-H 'client-secret: cf025d6f6fa13560b9d543745f48fe562b43b46e'
dbType Argument | Database Server Version |
MYSQL | MySQL 5.6 |
POSTGRESQL | PostgreSQL 9.3 |
MSSQL | SQL Server 2014 |
ORACLE_DB | Oracle Database 11g |