Skip to content

Run a read-only SQL query

POST
/sql.query
curl --request POST \
--url https://api.sancho-wms.pl/v1/sql.query \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "sql": "example", "integrationId": 1 }'

Runs one SQL query against the ERP database of an integration and returns every result set it produces, in order: one per SELECT. The query must only read. Sancho sends it to the database unchanged, so the SQL login the integration’s connector uses decides what it may do. Only an integration whose connector reads the ERP’s own database serves it, and only when both the integration and the key hold sql:read, which no integration or key has by default. Write the query in that database’s own dialect, and read its schema from INFORMATION_SCHEMA.TABLES and INFORMATION_SCHEMA.COLUMNS. Each result set comes back whole. A query that runs longer than 60 seconds, or whose results together are larger than 50 MB, is refused with 400: use TOP, WHERE, fewer columns and aggregates rather than reading whole tables. Dates come back as ISO strings, bigints as strings, binary values as { "type": "Buffer", "data": [bytes] }. A column name the query repeats holds an array of every value under that name: alias the columns to keep them apart. A query the database refuses answers 400 with the database’s own message, in the server’s language.

Media typeapplication/json
object
sql
required

One SQL query that only reads, in the ERP database’s own dialect.

string
>= 1 characters <= 20000 characters
integrationId
required
number

Example generated

{
"sql": "example",
"integrationId": 1
}

Successful response

Media typeapplication/json
SqlQueryResult
object
resultSets
required
Array<object>
SqlResultSet
object
columns
required
Array<object>
SqlColumn
object
name
required
string
type
required
string
rows
required
Array<object>
object
key
additional properties
login
required
string
Allowed values: readOnly default
durationMs
required
number
integrationId
required
number

Example

{
"login": "readOnly"
}

Bad request

Media typeapplication/json
error.BAD_REQUEST

The error information

object
message
required

The error message

string
code
required

The error code

string
issues

An array of issues that were responsible for the error

Array<object>
object
message
required
string

Example

{
"code": "BAD_REQUEST",
"message": "Bad request",
"issues": []
}

Unauthorized

Media typeapplication/json
error.UNAUTHORIZED

The error information

object
message
required

The error message

string
code
required

The error code

string
issues

An array of issues that were responsible for the error

Array<object>
object
message
required
string

Example

{
"code": "UNAUTHORIZED",
"message": "Unauthorized",
"issues": []
}

Payment required

Media typeapplication/json
error.PAYMENT_REQUIRED

The error information

object
message
required

The error message

string
code
required

The error code

string
issues

An array of issues that were responsible for the error

Array<object>
object
message
required
string

Example

{
"code": "PAYMENT_REQUIRED",
"message": "Payment required",
"issues": []
}

Forbidden

Media typeapplication/json
error.FORBIDDEN

The error information

object
message
required

The error message

string
code
required

The error code

string
issues

An array of issues that were responsible for the error

Array<object>
object
message
required
string

Example

{
"code": "FORBIDDEN",
"message": "Forbidden",
"issues": []
}

Not found

Media typeapplication/json
error.NOT_FOUND

The error information

object
message
required

The error message

string
code
required

The error code

string
issues

An array of issues that were responsible for the error

Array<object>
object
message
required
string

Example

{
"code": "NOT_FOUND",
"message": "Not found",
"issues": []
}

Unprocessable content

Media typeapplication/json
error.UNPROCESSABLE_CONTENT

The error information

object
message
required

The error message

string
code
required

The error code

string
issues

An array of issues that were responsible for the error

Array<object>
object
message
required
string

Example

{
"code": "UNPROCESSABLE_CONTENT",
"message": "Unprocessable content",
"issues": []
}

Too many requests

Media typeapplication/json
error.TOO_MANY_REQUESTS

The error information

object
message
required

The error message

string
code
required

The error code

string
issues

An array of issues that were responsible for the error

Array<object>
object
message
required
string

Example

{
"code": "TOO_MANY_REQUESTS",
"message": "Too many requests",
"issues": []
}

Internal server error

Media typeapplication/json
error.INTERNAL_SERVER_ERROR

The error information

object
message
required

The error message

string
code
required

The error code

string
issues

An array of issues that were responsible for the error

Array<object>
object
message
required
string

Example

{
"code": "INTERNAL_SERVER_ERROR",
"message": "Internal server error",
"issues": []
}

Service unavailable

Media typeapplication/json
error.SERVICE_UNAVAILABLE

The error information

object
message
required

The error message

string
code
required

The error code

string
issues

An array of issues that were responsible for the error

Array<object>
object
message
required
string

Example

{
"code": "SERVICE_UNAVAILABLE",
"message": "Service unavailable",
"issues": []
}