IBM Db2 SQL API
The SQL API from IBM Db2 — 3 operation(s) for sql.
The SQL API from IBM Db2 — 3 operation(s) for sql.
Every API here is available over the APIs.io API and to AI agents over MCP.
One button, every client — Claude, Cursor, VS Code and the rest.
https://apis.io/mcp
find_apisBrowse and filter every API in the catalog.get_api_artifactsOne API's artifacts, grouped by type.get_openapiThe primary OpenAPI for this API.find_similar_apisAPIs that look like this one.apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.resolveTurn a domain, URL or GitHub org into the provider it belongs to.find_cohortsEvery scored population of providers in the catalog.curl "https://apis.io/api/v1/apis/ibm-db2:ibm-db2-sql-api"
curl "https://apis.io/api/v1/apis?limit=25"
Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.
Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. By signing up you are subscribing to the APIs.io and API Evangelist newsletters — you can unsubscribe from any issue. See our Privacy Policy and Terms.
A second provider on the same verified email joins the account you already have.
openapi: 3.2.0
info:
title: Ibm Db2 SQL API
version: '4'
termsOfService: http://www.ibm.com/software/sla/sladb.nsf
x-github: https://github.ibm.com/cloud-api-docs/db2-saas
x-github-issues: https://github.ibm.com/cloud-api-docs/db2-saas/issues/new
x-last-updated: '2025-06-25'
x-sdk-supported-languages:
- java
- node
- go
- python
x-try-it-out-enabled: true
description: 'Operations tagged SQL across 2 of this provider''s published API definitions: ibm-db2-db2-on-cloud-v4-openapi.json, ibm-db2-openapi.yml. Each path carries the servers of the definition it was published in.'
servers:
- url: https://_HOSTNAME_VARIABLE_/dbapi/v4
security:
- authToken: []
- deploymentId: []
tags:
- name: sql
paths:
/sql_jobs:
post:
operationId: RunSQL
summary: Executes SQL statements
description: Executes one or more SQL statements as a background job. This endpoint returns a job ID that can be used to retrieve the results.
tags:
- sql
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/SQLJobCreate'
description: SQL script and execution options
required: true
x-codegen-request-body-name: SQL execution job
responses:
'201':
description: SQL execution job
content:
application/json:
schema:
$ref: '#/components/schemas/SQLJobSummary'
default:
description: Error payload
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorContainer'
x-sdk-operations:
request-examples:
go:
- name: Example request
example:
- type: code
source:
- "package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\t\"net/http\"\n\t\"io/ioutil\"\n)\n\nfunc main() {\n\n\turl := \"https://{HOSTNAME}/dbapi/v4/sql_jobs\"\n\n\tpayload := strings.NewReader(\"{\\\"commands\\\":\\\"select TABNAME, TABSCHEMA, OWNER from syscat.tables fetch first 5 rows only;select * from INVALID_TABLE fetch first 5 rows only;\\\",\\\"limit\\\":10,\\\"separator\\\":\\\";\\\",\\\"stop_on_error\\\":\\\"no\\\"}\")\n\n\treq, _ := http.NewRequest(\"POST\", url, payload)\n\n\treq.Header.Add(\"content-type\", \"application/json\")\n\treq.Header.Add(\"authorization\", \"Bearer {AUTH_TOKEN}\")\n\treq.Header.Add(\"x-deployment-id\", \"{DEPLOYMENT_ID}\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := ioutil.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}"
java:
- name: Example request
example:
- type: code
source:
- "OkHttpClient client = new OkHttpClient();\n\nMediaType mediaType = MediaType.parse(\"application/json\");\nRequestBody body = RequestBody.create(mediaType, \"{\\\"commands\\\":\\\"select TABNAME, TABSCHEMA, OWNER from syscat.tables fetch first 5 rows only;select * from INVALID_TABLE fetch first 5 rows only;\\\",\\\"limit\\\":10,\\\"separator\\\":\\\";\\\",\\\"stop_on_error\\\":\\\"no\\\"}\");\nRequest request = new Request.Builder()\n .url(\"https://{HOSTNAME}/dbapi/v4/sql_jobs\")\n .post(body)\n .addHeader(\"content-type\", \"application/json\")\n .addHeader(\"authorization\", \"Bearer {AUTH_TOKEN}\")\n .addHeader(\"x-deployment-id\", \"{DEPLOYMENT_ID}\")\n .build();\n\nResponse response = client.newCall(request).execute();"
node:
- name: Example request
example:
- type: code
source:
- "var http = require(\"https\");\n\nvar options = {\n \"method\": \"POST\",\n \"hostname\": \"{HOSTNAME}\",\n \"port\": null,\n \"path\": \"/dbapi/v4/sql_jobs\",\n \"headers\": {\n \"content-type\": \"application/json\",\n \"authorization\": \"Bearer {AUTH_TOKEN}\",\n \"x-deployment-id\": \"{DEPLOYMENT_ID}\"\n }\n};\n\nvar req = http.request(options, function (res) {\n var chunks = [];\n\n res.on(\"data\", function (chunk) {\n chunks.push(chunk);\n });\n\n res.on(\"end\", function () {\n var body = Buffer.concat(chunks);\n console.log(body.toString());\n });\n});\n\nreq.write(JSON.stringify({\n commands: 'select TABNAME, TABSCHEMA, OWNER from syscat.tables fetch first 5 rows only;select * from INVALID_TABLE fetch first 5 rows only;',\n limit: 10,\n separator: ';',\n stop_on_error: 'no'\n}));\nreq.end();"
python:
- name: Example request
example:
- type: code
source:
- "import http.client\n\nconn = http.client.HTTPSConnection(\"{HOSTNAME}\")\n\npayload = \"{\\\"commands\\\":\\\"select TABNAME, TABSCHEMA, OWNER from syscat.tables fetch first 5 rows only;select * from INVALID_TABLE fetch first 5 rows only;\\\",\\\"limit\\\":10,\\\"separator\\\":\\\";\\\",\\\"stop_on_error\\\":\\\"no\\\"}\"\n\nheaders = {\n 'content-type': \"application/json\",\n 'authorization': \"Bearer {AUTH_TOKEN}\",\n 'x-deployment-id': \"{DEPLOYMENT_ID}\"\n }\n\nconn.request(\"POST\", \"/dbapi/v4/sql_jobs\", payload, headers)\n\nres = conn.getresponse()\ndata = res.read()\n\nprint(data.decode(\"utf-8\"))"
curl:
- name: Example request
example:
- type: code
source:
- "curl -X POST \\\n https://{HOSTNAME}/dbapi/v4/sql_jobs \\\n -H 'authorization: Bearer {AUTH_TOKEN}' \\\n -H 'content-type: application/json' \\\n -H 'x-deployment-id: {DEPLOYMENT_ID}' \\\n -d '{\"commands\":\"select TABNAME, TABSCHEMA, OWNER from syscat.tables fetch first 5 rows only;select * from INVALID_TABLE fetch first 5 rows only;\",\"limit\":10,\"separator\":\";\",\"stop_on_error\":\"no\"}'"
servers:
- url: https://_HOSTNAME_VARIABLE_/dbapi/v4
/sql_jobs/{id}:
get:
operationId: FetchSQLResults
summary: Fetches partial results of a SQL job execution
description: Returns the current status of a SQL job execution along with any results of SQL statements that have already been executed. Clients are supposed to poll this endpoint until the status returned is either 'completed', which indicates all SQL statements have completed executing, or 'failed', which indicates the job failed to execute and therefore is considered terminated. The returned list of results is not cumulative. That means, results that were fetched in a previous call will not be returned again, only new results (i.e. that were not fetched yet) will be included. For example, assuming a job with 10 SQL statements, the first call returns status "running" and 6 results, the second call returns status "running" and an empty list of results, a third call status "completed" and 4 results. Any subsequent calls would return status "completed" and an empty list of results.
tags:
- sql
parameters:
- name: id
in: path
description: ID of the SQL execution job
required: true
schema:
type: string
responses:
'200':
description: Result of a SQL job
content:
application/json:
schema:
$ref: '#/components/schemas/SQLJobResults'
default:
description: Error payload
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorContainer'
x-sdk-operations:
request-examples:
go:
- name: Example request
example:
- type: code
source:
- "package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io/ioutil\"\n)\n\nfunc main() {\n\n\turl := \"https://{HOSTNAME}/dbapi/v4/sql_jobs/{id}\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\treq.Header.Add(\"content-type\", \"application/json\")\n\treq.Header.Add(\"authorization\", \"Bearer {AUTH_TOKEN}\")\n\treq.Header.Add(\"x-deployment-id\", \"{DEPLOYMENT_ID}\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := ioutil.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}"
java:
- name: Example request
example:
- type: code
source:
- "OkHttpClient client = new OkHttpClient();\n\nRequest request = new Request.Builder()\n .url(\"https://{HOSTNAME}/dbapi/v4/sql_jobs/{id}\")\n .get()\n .addHeader(\"content-type\", \"application/json\")\n .addHeader(\"authorization\", \"Bearer {AUTH_TOKEN}\")\n .addHeader(\"x-deployment-id\", \"{DEPLOYMENT_ID}\")\n .build();\n\nResponse response = client.newCall(request).execute();"
node:
- name: Example request
example:
- type: code
source:
- "var http = require(\"https\");\n\nvar options = {\n \"method\": \"GET\",\n \"hostname\": \"{HOSTNAME}\",\n \"port\": null,\n \"path\": \"/dbapi/v4/sql_jobs/{id}\",\n \"headers\": {\n \"content-type\": \"application/json\",\n \"authorization\": \"Bearer {AUTH_TOKEN}\",\n \"x-deployment-id\": \"{DEPLOYMENT_ID}\"\n }\n};\n\nvar req = http.request(options, function (res) {\n var chunks = [];\n\n res.on(\"data\", function (chunk) {\n chunks.push(chunk);\n });\n\n res.on(\"end\", function () {\n var body = Buffer.concat(chunks);\n console.log(body.toString());\n });\n});\n\nreq.end();"
python:
- name: Example request
example:
- type: code
source:
- "import http.client\n\nconn = http.client.HTTPSConnection(\"{HOSTNAME}\")\n\nheaders = {\n 'content-type': \"application/json\",\n 'authorization': \"Bearer {AUTH_TOKEN}\",\n 'x-deployment-id': \"{DEPLOYMENT_ID}\"\n }\n\nconn.request(\"GET\", \"/dbapi/v4/sql_jobs/{id}\", headers=headers)\n\nres = conn.getresponse()\ndata = res.read()\n\nprint(data.decode(\"utf-8\"))"
curl:
- name: Example request
example:
- type: code
source:
- "curl -X GET \\\n https://{HOSTNAME}/dbapi/v4/sql_jobs/{id} \\\n -H 'authorization: Bearer {AUTH_TOKEN}' \\\n -H 'content-type: application/json' \\\n -H 'x-deployment-id: {DEPLOYMENT_ID}'"
servers:
- url: https://_HOSTNAME_VARIABLE_/dbapi/v4
/sql_query_export:
post:
operationId: FetchSQLStatementResults
summary: Returns the results of a SQL query to CSV
description: Executes the specified SQL query and returns the data as a CSV file. The amount of data returned is limited to 100,000 rows.
tags:
- sql
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/SQLStatement'
description: The SQL query to be executed
required: true
x-codegen-request-body-name: SQL query
responses:
'200':
description: CSV file containing query results
content:
text/csv:
schema:
type: string
format: binary
default:
description: Error payload
content:
text/csv:
schema:
$ref: '#/components/schemas/ErrorContainer'
x-sdk-operations:
request-examples:
go:
- name: Example request
example:
- type: code
source:
- "package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\t\"net/http\"\n\t\"io/ioutil\"\n)\n\nfunc main() {\n\n\turl := \"https://{HOSTNAME}/dbapi/v4/sql_query_export\"\n\n\tpayload := strings.NewReader(\"{\\\"command\\\":\\\"<ADD STRING VALUE>\\\"}\")\n\n\treq, _ := http.NewRequest(\"POST\", url, payload)\n\n\treq.Header.Add(\"content-type\", \"text/csv\")\n\treq.Header.Add(\"authorization\", \"Bearer {AUTH_TOKEN}\")\n\treq.Header.Add(\"x-deployment-id\", \"{DEPLOYMENT_ID}\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := ioutil.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}"
java:
- name: Example request
example:
- type: code
source:
- "OkHttpClient client = new OkHttpClient();\n\nMediaType mediaType = MediaType.parse(\"application/json\");\nRequestBody body = RequestBody.create(mediaType, \"{\\\"command\\\":\\\"<ADD STRING VALUE>\\\"}\");\nRequest request = new Request.Builder()\n .url(\"https://{HOSTNAME}/dbapi/v4/sql_query_export\")\n .post(body)\n .addHeader(\"content-type\", \"text/csv\")\n .addHeader(\"authorization\", \"Bearer {AUTH_TOKEN}\")\n .addHeader(\"x-deployment-id\", \"{DEPLOYMENT_ID}\")\n .build();\n\nResponse response = client.newCall(request).execute();"
node:
- name: Example request
example:
- type: code
source:
- "var http = require(\"https\");\n\nvar options = {\n \"method\": \"POST\",\n \"hostname\": \"{HOSTNAME}\",\n \"port\": null,\n \"path\": \"/dbapi/v4/sql_query_export\",\n \"headers\": {\n \"content-type\": \"text/csv\",\n \"authorization\": \"Bearer {AUTH_TOKEN}\",\n \"x-deployment-id\": \"{DEPLOYMENT_ID}\"\n }\n};\n\nvar req = http.request(options, function (res) {\n var chunks = [];\n\n res.on(\"data\", function (chunk) {\n chunks.push(chunk);\n });\n\n res.on(\"end\", function () {\n var body = Buffer.concat(chunks);\n console.log(body.toString());\n });\n});\n\nreq.write(JSON.stringify({command: '<ADD STRING VALUE>'}));\nreq.end();"
python:
- name: Example request
example:
- type: code
source:
- "import http.client\n\nconn = http.client.HTTPSConnection(\"{HOSTNAME}\")\n\npayload = \"{\\\"command\\\":\\\"<ADD STRING VALUE>\\\"}\"\n\nheaders = {\n 'content-type': \"text/csv\",\n 'authorization': \"Bearer {AUTH_TOKEN}\",\n 'x-deployment-id': \"{DEPLOYMENT_ID}\"\n }\n\nconn.request(\"POST\", \"/dbapi/v4/sql_query_export\", payload, headers)\n\nres = conn.getresponse()\ndata = res.read()\n\nprint(data.decode(\"utf-8\"))"
curl:
- name: Example request
example:
- type: code
source:
- "curl -X POST \\\n https://{HOSTNAME}/dbapi/v4/sql_query_export \\\n -H 'authorization: Bearer {AUTH_TOKEN}' \\\n -H 'content-type: text/csv' \\\n -H 'x-deployment-id: {DEPLOYMENT_ID}' \\\n -d '{\"command\":\"<ADD STRING VALUE>\"}'"
servers:
- url: https://_HOSTNAME_VARIABLE_/dbapi/v4
components:
schemas:
ErrorContainer:
type: object
description: Error response containing one or more error messages
required:
- trace
- errors
properties:
trace:
type: string
description: Unique ID assigned by the server that identifies the request that generated the error
errors:
type: array
description: List of errors
items:
$ref: '#/components/schemas/ErrorModel'
SQLJobCreate:
type: object
required:
- commands
- limit
- separator
- stop_on_error
properties:
commands:
type: string
description: The SQL script to be executed
example: select TABNAME, TABSCHEMA, OWNER from syscat.tables fetch first 5 rows only;select * from INVALID_TABLE fetch first 5 rows only;
limit:
type: integer
format: int32
description: Maximum number of rows that will be fetched for each result set.
example: 10
default: 1000
separator:
type: string
description: SQL statement terminator. A character that is used to mark the end of a SQL statement when the provided SQL script contains multiple statements.
example: ;
stop_on_error:
type: string
description: If 'yes', the job stops executing at the first statement that returns an error. If 'no', the job continues executing if one or more statements returns an error.
example: 'no'
ErrorModel:
type: object
description: Error information
required:
- code
- message
properties:
code:
type: string
description: Error code succinctly identifying the problem
enum:
- authentication_failure
- database_error
- forbidden
- internal_server_error
- invalid_authentication_token
- invalid_content_type
- invalid_api_endpoint
- invalid_parameters
- invalid_request_payload
- not_found
- resource_already_exists
- session_expired
- unavailable
message:
type: string
description: Explanation of the problem and possible solutions
target:
$ref: '#/components/schemas/ErrorTargetModel'
more_info:
type: string
description: URL where more information about the error can be found (if available)
SQLStatement:
type: object
required:
- command
properties:
command:
type: string
description: The SQL statement to execute
SQLStatementResult:
type: object
required:
- command
- runtime_seconds
properties:
command:
type: string
description: The SQL statement
columns:
type: array
items:
type: string
description: List of column names in the result set
rows:
type: array
description: Rows of data returned in the result set
items:
type: array
items:
type: string
rows_count:
type: integer
format: int32
description: Number of rows returned
limit:
type: integer
format: int32
description: Maximum number of rows that will be fetched when the command returns a result set.
last_inserted:
type: integer
description: The index of the last inserted row if available
rows_affected:
type: integer
description: Number of rows updated or inserted by the command
runtime_seconds:
type: number
format: double
description: Execution time in seconds
error:
type: string
description: Error message generated when executing the command if any
ErrorTargetModel:
type: object
description: Field or parameter related to an error
required:
- type
- name
properties:
type:
type: string
description: Field type
enum:
- field
- parameter
- header
name:
type: string
description: Name of the problematic field (with dot-syntax if necessary), query parameter, or header
SQLJobResults:
type: object
description: Contains the results of executing the SQL statements associated with a SQL execution job
required:
- id
- status
properties:
id:
type: string
description: The SQL execution job ID
status:
type: string
description: Job status
enum:
- running
- failed
- completed
results:
type: array
items:
$ref: '#/components/schemas/SQLStatementResult'
SQLJobSummary:
type: object
required:
- id
- commands_count
properties:
id:
type: string
description: The SQL execution job ID
commands_count:
type: integer
format: int32
description: Number of SQL statements to be executed
default: 1000
limit:
type: integer
format: int32
description: Maximum number of rows that will be fetched for each result set
securitySchemes:
authToken:
type: apiKey
in: header
name: Authorization
description: Authorize using **Bearer [access_token]**. The access token can be obtained by authenticating with the **/auth/tokens** endpoint or [use the API key to generate an IAM Bearer Token](https://cloud.ibm.com/docs/account?topic=account-iamtoken_from_apikey).
deploymentId:
type: apiKey
in: header
name: X-Deployment-Id
description: The deployment id of the service, which can be obtained after provision. When providing the deployment id in the header, use URL encoding. For example, ":" should be escaped as "%3A", and "/" should be escaped as "%2F".
x-refined-from:
- ibm-db2-db2-on-cloud-v4-openapi.json
- ibm-db2-openapi.yml