Using the REST interface with Db2

Important: IBM Cloud Pak® for Data Version 4.7 will reach end of support (EOS) on 31 July, 2025. For more information, see the Discontinuance of service announcement for IBM Cloud Pak for Data Version 4.X.

Upgrade to IBM Software Hub Version 5.1 before IBM Cloud Pak for Data Version 4.7 reaches end of support. For more information, see Upgrading IBM Software Hub in the IBM Software Hub Version 5.1 documentation.

Using the Db2® REST interface is extensively documented in the Db2 documentation. However, some differences exist in usage methods between Db2 on Cloud Pak for Data and the standalone Db2.

Before you begin

Request specific privileges that you need. For more information, see Required privileges for working with REST endpoints in Db2.

Enablement

The biggest difference is in enablement. To enable the REST interface on Cloud Pak for Data, follow the steps in Enabling the Db2 REST interface.

Db2 REST documentation that can be used as is

Db2 REST documentation that requires some changes for Cloud Pak for Data

The following topics apply to the REST interface on Cloud Pak for Data, but with some differences:
  • Defining a REST SQL service: The sentence, "Before you define a service, you must first set up the REST server metadata, either by activating and initialing REST service capability or by issuing the following REST call" does not apply to the REST interface on Cloud Pak for Data because the service is enabled differently. You must issue the REST call that is described in Setting up Db2 REST server metadata on Cloud Pak for Data.
  • Authenticating REST commands: Some values that are required to authenticate REST calls are pre-specified in the Db2 REST implementation on Cloud Pak for Data, but you must pass some values when authenticating or the request is rejected.

    All REST calls require an authentication token to confirm the identity of the issuer. If you are authenticating against the Cloud Pak for Data database instance in the cluster that the REST service belongs to, you do not need to specify valid values for dbHost, dbName and dbPort. These values are pre-specified. For dbHost and dbName, if you pass empty strings, the pre-specified values are used. For dbPort, if you pass -1, the pre-specified values are used. You need to pass True for isSSLConnection to leverage the pre-specified values. The following example would be valid:
    
    json = {
    "dbParms": {
    "dbHost": "",
    "dbName": "",
    "dbPort": -1,
    "isSSLConnection": True,
    "username": username,
    "password": password
    },
    "expiryTime": "24h"
    }
    

    If you wish to authenticate with a different database instance, you can specify the parameters for that database instance as necessary.