Jump to contents

GridDB Web API Reference

Revision: 4.6.0-400

1 Web API

1.1 Overview

GridDB provides a Web API to register rows, acquire rows and execute a TQL and a SQL statement for GridDB cluster. The Web API is configured as a web application.

Web API
Web API

The functions of GridDB Web API are shown below.

  • Row acquisition
    • Acquires rows from the container.
  • Row registration
    • Registers rows to the container.
  • Database connection confirmation
    • Checks connection to a database.
  • Container list acquisition
    • Acquires a container list from a database.
  • Container information acquisition
    • Acquires container information (column etc.) from a container
  • TQL statement execution
    • Executes multiple SQL statements and acquires the results.
  • Row deletion
    • Deletes a row from a container.
  • Creating a container
    • Creates a new container for a database.
  • Deleting container
    • Deletes a container from a database.
  • SQL SELECT execution
    • Executes a SQL SELECT statement

1.2 Using Web API

To use gs_admin, Java has to be installed beforehand. The compatible versions are as follows.

  • Oracle Java 8
  • Oracle Java 11
  • RedHat OpenJDK 8
  • RedHat OpenJDK 11

The procedure to install and configure Web API is as follows.

  1. Installation of a library package.
  2. Installation of Web API package.
  3. Setting of the destination cluster
  4. Setting of the Web API operation (optional)
  5. Setting of the log output destination (optional)

1.2.1 Installation of a library package.

Install the following packages.

  • Java library package (griddb-ee-java_lib-XX.X-linux.x86_64.rpm)

Log into a machine installed with the Web API as a root user, and install the package using the command below.

# rpm -Uvh griddb-ee-java_lib-X.X.X-linux.x86_64.rpm

*X.X.X indicates the GridDB version.

1.2.2 Installation of Web API package.

Install the Web API package (griddb-ee-webapi-XX.X-linux.x86_64.rpm).

Log into a machine installed with the Web API as a root user, and install the package using the command below.

# rpm -Uvh griddb-ee-webapi-X.X.X-linux.x86_64.rpm

*X.X.X indicates the GridDB version.

After installing, Web API .jar file and configuration files are installed as follows:

/usr/griddb-webapi/griddb-webapi.jar                     : Web API jar file

/var/lib/gridstore/webapi/conf/griddb_webapi.properties  : Configuration file
                              /repository.json           : Cluster information definition file
                         /log                            : Log output directory

1.2.3 Setting of the destination cluster

Specify the information of the cluster to be connected from the Web API in the cluster information definition file ( /var/lib/gridstore/webapi/conf/repository.json ).

Based on the value of the cluster definition file (gs_cluster.json) of the cluster to be connected, specify the cluster configuration method to "mode", and the address information corresponding to the method.

Parameter JSON Data type Description
clusters array An array of the cluster information
name string cluster name
mode string Connection method (MULTICAST/FIXED_LIST/PROVIDER )
(mode=MULTICAST)
address string Multicast address for row registration and acquisition
port int Multicast port for row registration and acquisition
jdbcAddress string Multicast address for SQL SELECT execution
jdbcPort int Multicast port for SQL SELECT execution
(mode=FIXED_LIST)
transactionMember string Connection destination list for row registration and acquisition
sqlMember string Connection destination list for SQL SELECT execution
(mode=PROVIDER)
providerUrl string Provider URL for all functions

Example: In case of the multicast method

[Memo]

  • If the contents of repository.json are invalid (format error, mandatory parameter not defined, etc.), Web API startup will result in an error.

1.2.4 Setting of the Web API operation (optional)

Configure Web API behaviors by setting the configuration file (/var/lib/gridstore/webapi/conf/griddb_webapi.properties).

If not setting it will work with the default values. Configure the values according to the system.

1.2.4.1 GridDB configuration

Field Description Default value
failoverTimeout Specify the failover time (seconds) to repeat retries after detecting a node failure in Web API access to GridDB. 5
transactionTimeout The timeout time (second) of transaction. 30
containerCacheSize The maximum number of the container information on the container cache. 100

1.2.4.2 Web API configuration

Field Description Default value
port Web API service port (integer from 1 to 65535) 8081
maxGetRowSize The upper limit of the size for row acquisition , TQL execution, and SQL SELECT execution (MB) (integer from 1 to 2048) 20
maxPutRowSize The upper limit of the size for row registration.(MB) (1-2048) 20
loginTimeout The connection timeout time (second) for SQL SELECT execution
(An integer value can be specified. When it is less than 0, SQL SELECT statement can not be executed.)
5
maxQueryNum Maximum number of queries that can be included in one request (integer from 0 to 100) 10
maxLimit Maximum number of rows that can be acquired at one time when executing SQL or SQL (integer of 1 or more) 10000
timeZone Specify the time (in ±hh:mm or ±hhmm), time zone ID (only supports "Z"), or AUTO (takes over the JavaVM environment) as a time zone to be used in the offset calculation to retrieve time information in SQL and TQL. Z
authenticationMethod Specify either INTERNAL (internal authentication) or LDAP (LDAP authentication) as an authentication method to be used. dependent on the GridDB cluster settings
notificationInterfaceAddress To configure the cluster network in multicast mode when multiple network interfaces are available, specify the IP address of the interface to receive the multicast packets from. OS-dependent
sslMode For SSL connection settings, specify DISABLED (SSL is invalid), REQUIRED (SSL is valid), or VERIFY (SSL is valid and performs server certificate verification). DISABLED

[Memo]

  • The Web API needs to be restarted to reflect the environment settings.
  • For details on LDAP authentication and SSL connection, see the GridDB Features Reference (GridDB_FeaturesReference.html).
  • If the SSL connection settings are invalid on the GridDB cluster, SSL communications cannot be enabled regardless of the settings of this tool.
  • To specify VERIFY for the settings for SSL communications (sslMode), a certificate by the Certificate Authority (CA) is required; import the certificate using the keytool command. To set a truststore (-Djavax.net.ssl.trustStore) and a password (-Djavax.net.ssl.trustStorePassword) as arguments upon launching java, specify them for the environment variable GS_COMMON_JVM_ARGS. Note that the Web API does not support the checking of the expiration date of a CA certificate to ensure it is valid.
  • Set the environment variable GS_COMMON_JVM_ARGS in /etc/environment, referring to the example below. Restart the Web API to apply the settings.

Example:

GS_COMMON_JVM_ARGS="-Djavax.net.ssl.trustStore=/var/lib/gridstore/admin/keystore.jks -Djavax.net.ssl.trustStorePassword=changeit"
  • To enable SSL communications between the client and the Web API ., set up /usr/griddb-webui/application.properties by referring to the following:

Example:

server.ssl.enabled=true
server.port=8443
server.ssl.key-store-type=JKS
server.ssl.key-store=/var/lib/gridstore/admin/keystore.jks
server.ssl.key-store-password=changeit
server.ssl.key-alias=tomcat

1.2.5 Setting of the log output destination (optional)

The Web API logs are output to the following directory by default.

/var/lib/gridstore/webapi/log

To change the output directory, edit the following file:

/var/lib/gridstore/webapi/conf/logback.xml

1.2.6 Starting and Stopping

Web API applications can be started and stopped using the service command.

# service griddb-webapi [start|stop|status|restart]

1.3 Common functions (HTTP request/response)

This chapter describes the HTTP request /response part common to each function.

1.3.1 URI

The URI to be accessed when using the Web API.

http://(Web API server IP) :(port)/griddb/v2/(command path)

[Memo]

  • Specify path of each function as ":path".
  • It is not allowed in this version's GridDB WEB APIs that clusters, databases and containers which name contains any special characters('-', '.', '/', '=') are specified in the path.

1.3.2 Request header

Specify the following headers to the request header. (Common to all APIs)

Field Description Required
Content-Type "application/json; charset=UTF-8"
Authorization Specify the user and password to access the GridDB in the user: password format (Basic authentication)

1.3.3 Request body

Specify the request body as JSON format. Please refer to the JSON format of each functions.

[Memo]

  • Write JSON format data in UTF-8.
  • Write the date in UTC and in the following format:
    • YYYY-MM-DDThh:mm:ss.SSSZ
  • Otherwise, an error will occur.
    • Example:
      • 2016/01/17T14: 32: 33.888Z ... Error due to year, month and date separator error
      • 2016-01-18 ... Error because time is not specified

1.3.4 Response code

Refer to the paragraph of each function for the response code.

1.3.5 Response body

Refer to the section on each function for the response body when the processing succeeds.

If processing fails, an error message is returned in the following format.

1.4 Row acquisition

This function acquire the rows from the container (table). It is also possible to narrow down the rows to be acquired by specifying conditions.

Path

/:cluster/dbs/:database/containers/:container/rows

Item Description
:cluster cluster name
:database Database name (specify "public" for a public database)
:container Container (table) name

HTTP method

POST

Request header

Refer to the request header.

Request body

Item Description JSON data type Required
/offset Acquisition start position An integer from 0 -
/limit The number of rows to be acquired An integer from 1
/condition Condition expression string -
/sort Sorting condition (column name asc or desc) string -

[Memo]

  • If the value specified by limit is greater than maxLimit in the configuration file, the value of maxLimit is used in the limit clause.

Example: Acquires row data with a column "id" value of 50 or more, sorts it in descending order by the value of "id", and acquires 100 values from the 11th

Response code

Code Description
200 Success
400 Incorrect request data
401 An authentication error, a connection error
404 Specified resource is not found
500 An error occurs in Web API or GridDB

Response body

Acquired rows will be returned as the following JSON data.

Item Description JSON data type
/columns An array of column information Array
/columns/name Column name string
/columns/type JSON Data type string
/columns/rows An array of the rows Array
/total Number of rows acquired when offset and limit are ignored Number
/offset Acquisition start position Number
/limit Number of acquisitions applied Number

Example:

Depending on the column data type, column values with the following JSON data type will be returned.

Classification JSON Data type JSON data type Example
Primitive Boolean type BOOL Boolean (true/false) true
String type STRING string "GridDB"
Integer type BYTE/SHORT/INTEGER/LONG Number 512
Floating point type FLOAT/DOUBLE Number 593.5
Date and time type TIMESTAMP Text string
・UTC
・format
YYYY-MM-DDThh:mm:ss.SSSZ
"2016-01-16T10:25:00.253Z"
Spatial-type GEOMETRY Text string (WKT representation) POLYGON((0 0,10 0,10 10,0 10,0 0))
Array Boolean type BOOL Array of boolean values [true, false, true]\
String type STRING Array of text string values ["A","B","C"]
Integer type BYTE/SHORT/INTEGER/LONG Array of numbers [100, 39, 535]
Floating point type FLOAT/DOUBLE Array of numbers [3.52, 6.94, 1.83]
Date and time type TIMESTAMP Array of text string values
(Format is same as the primitive one)
["2016-01-16T10:25:00.253Z", "2016-01-17T01:42:53.038Z"]

[Memo]

  • BLOB type is unsupported. An empty string will be returned when specifying the container that has the BLOB column.
  • In case that column value is NULL, null will be returned for the column in JSON data.

1.5 Row registration

This function registers the rows to the container.

Specify the rows to be registered in JSON format. Multiple rows can be registered in one container.

[Memo]

  • The data of one row / multiple rows can be specified and registered into one container.
  • The container to be registered must exist.
  • When the container has a row key, if a row has the row key that already exists in the container will be updated, otherwise a row will be newly created.
  • When the container has no row key, a row will be newly created.
  • When an exception occurs during row registration processing, only some rows may be registered. Therefore, when retrying with an HTTP client when an exception occurs, the same row data may be registered duplicately in a container has no row key.

Path

/:cluster/dbs/:database/containers/:container/rows

Item Description
:cluster cluster name
:database Database name (specify "public" for a public database)
:container Container (table) name

HTTP method

PUT

Request header

Refer to the request header.

Request body

Specify the rows as following JSON format.

Item Description JSON data type Required
/(row) Row (an array of column values) Array

Example:

Depending on the column data type, describe a column value with the following JSON data type.

Classification JSON Data type JSON data type Example
Primitive Boolean type BOOL Boolean value ( true or false )
or character string ("true" or "false")
true
String type STRING string "GridDB"
Integer type BYTE/SHORT/INTEGER/LONG Number or text string 512
Floating point type FLOAT/DOUBLE Number or text string 593.5
Date and time type TIMESTAMP Text string
・UTC
・format
YYYY-MM-DDThh:mm:ss.SSSZ
"2016-01-16T10:25:00.253Z"
Spatial-type GEOMETRY Text string (WKT representation) POLYGON((0 0,10 0,10 10,0 10,0 0))
Array Boolean type BOOL Boolean array or string array [true, false, true]
String type STRING Array of text string values ["A","B","C"]
Integer type BYTE/SHORT/INTEGER/LONG Numeric array or string array [100, 39, 535]
Floating point type FLOAT/DOUBLE Numeric array or string array [3.52, 6.94, 1.83]
Date and time type TIMESTAMP Array of text string values
(Format is same as the primitive one)
["2016-01-16T10:25:00.253Z", "2016-01-17T01:42:53.038Z"]

[Memo]

  • BLOB type is unsupported. An error occurs when specifying the container that has the BLOB column.
  • If a NULL value (null of JSON data type) is specified as column value, it operates as follows:
    • When the NOT NULL constraint is specified for the column : Registration error will occur.
    • Otherwise : A NULL value will be registered.

Response code

Code Description
200 Success
400 Incorrect request data
401 An authentication error, a connection error
404 Specified resource is not found
500 An error occurs in Web API or GridDB

Response body

If the process is successful, nothing is returned.

Please refer to response body in case of failure.

1.6 Database connection confirmation

Check the connection to the specified database.

Path

/:cluster/dbs/:database/checkConnection

Item Description
:cluster cluster name
:database Database name (specify "public" for a public database)

HTTP method

GET

Request header

Refer to the request header.

Request parameter

Item Description JSON Data type Required
/timeout Timeout value only for this API (seconds) An integer from 0 -

Response code

Code Description
200 Success
400 Incorrect request data
401 An authentication error, a connection error
500 An error occurs in Web API or GridDB

Response body

If the process is successful, nothing is returned.

Please refer to response body in case of failure.

1.7 Container list acquisition

Get a list of containers and tables. It is also possible to narrow down the containers to be acquired by specifying conditions.

Path

/:cluster/dbs/:database/containers

Item Description
:cluster cluster name
:database Database name (specify "public" for a public database)

HTTP method

GET

Request header

Refer to the request header.

Request parameter

Item Description JSON data type Required
/type Type of containers to be acquired Text string(collection or timeseries) -
/limit The number of rows to be acquired An integer from 0
/offset Acquisition start position An integer from 0 -
/sort Sorting expression string -

[Memo]

  • If "limit" is set to 0 (zero), all rows matching the condition can be acquired.
  • offset can be used together with "limit".

Response code

Code Description
200 Success
400 Incorrect request data
401 An authentication error, a connection error
500 An error occurs in Web API or GridDB

Response body

Acquired rows will be returned as the following JSON data.

Item Description JSON data type
/names Array of container names Array
/total Number of acquisitions when offset and limit are ignored Number
/offset Acquisition start position Number
/limit Number of acquisitions applied Number

Example:

1.8 Container information acquisition

Get the information on a container or a table.

Path

/:cluster/dbs/:database/containers/:container/info

Item Description
:cluster cluster name
:database Database name (specify "public" for a public database)
:container Container (table) name

HTTP method

GET

Request header

Refer to the request header.

Request body

-

Response code

Code Description
200 Success
400 Incorrect request data
401 An authentication error, a connection error
404 Specified resource is not found
500 An error occurs in Web API or GridDB

Response body

Item Description JSON data type
/container_name An array of column information Array
/container_type Column name string
/rowkey Column name string
/columns Information of columns Array
/columns/name Column name string
/columns/type Data type of column string
/columns/index Index Array

Example:

[Memo]

  • Containers with composite row keys and composite indexes are not supported. When the command is executed, IllegalStateException occurs.

1.9 TQL command execution

Execute a TQL statement. Multiple TQL statements can be sent at once. The value of specific columns can be set to acquire in the execution result.

Path

/:cluster/dbs/:database/tql

Item Description
:cluster cluster name
:database Database name (specify "public" for a public database)

HTTP method

POST

Request header

Refer to the request header.

Request body

Item Description JSON data type Required
/name Target container name string
/stmt TQL statement string
/columns Array of acquisition column names Array -

[Memo]

  • If the value specified by limit in TQL is greater than maxLimit in the configuration file, the value of maxLimit is used in the limit clause.

Example:

Response code

Code Description
200 Success
400 Incorrect request data
401 An authentication error, a connection error
404 Specified resource is not found
500 An error occurs in Web API or GridDB

Response body

Item Description JSON data type
/columns An array of column information Array
/columns/name Column name string
/columns/type JSON Data type string
/results TQL execution results Array
/total Number of acquisitions when offset and limit are ignored Number
/offset Acquisition start position Number
/limit Number of acquisitions applied Number

[Memo]

  • If the SQL statement is an aggregate operation, total, offset, and limit are not included.

Example:

1.10 Row deletion

This function deletes the rows from the container (table).

Path

/:cluster/dbs/:database/containers/:container/rows

Item Description
:cluster cluster name
:database Database name (specify "public" for a public database)
:container Container (table) name

HTTP method

DELETE

Request header

Refer to the request header.

Request body

Item Description JSON data type Required
/(key) Row key Array -

Example:

Response code

Code Description
204 Success
400 Incorrect request data
401 An authentication error, a connection error
404 Specified resource is not found
500 An error occurs in Web API or GridDB

Response body

If the process is successful, nothing is returned.

Please refer to response body in case of failure.

[Memo]

  • Containers with composite row keys are not supported. When the command is executed, IllegalStateException occurs.

1.11 Creating a container

Create a container.

Path

/:cluster/dbs/:database/containers

Item Description
:cluster cluster name
:database Database name (specify "public" for a public database)

HTTP method

POST

Request header

Refer to the request header.

Request body

Item Description JSON data type
/container_name An array of column information Array
/container_type Column name string
/rowkey Column name string
/columns Information of columns Array
/columns/name Column name string
/columns/type Data type of column string
/columns/index Index Array

Example:

Response code

Code Description
201 Success
400 Incorrect request data
401 An authentication error, a connection error
409 The specified container already exists.
500 An error occurs in Web API or GridDB

Response body

If the process is successful, nothing is returned.

Please refer to response body in case of failure.

[Memo]

  • Composite row keys and composite indexes are not supported.

1.12 Container deletion

Delete a container

Path

/:cluster/dbs/:database/containers

Item Description
:cluster cluster name
:database Database name (specify "public" for a public database)

HTTP method

DELETE

Request header

Refer to the request header.

Request body

Item Description JSON data type Required
/(name) <Container name> Array -

Example:

Response code

Code Description
204 Success
400 Incorrect request data
401 An authentication error, a connection error
500 An error occurs in Web API or GridDB

Response body

If the process is successful, nothing is returned.

Please refer to response body in case of failure.

1.13 SQL SELECT execution

This function executes a SQL SELECT statement in a GridDB database.

Path

/:cluster/dbs/:database/sql

Item Description
:cluster cluster name
:database Database name (specify "public" for a public database)

HTTP method

POST

Request header

Refer to the request header.

Request body

Specify a SQL SELECT statement as following JSON format.

Item Description JSON data type Required
/type Type of query statement (only "sql-select" can be specified) string
/stmt A SQL SELECT statement string

Example:

Response code

Code Description
200 Success
400 Incorrect request data
401 An authentication error, a connection error
404 Specified resource is not found
500 An error occurs in Web API or GridDB

Response body

Item Description JSON data type
/columns An array of column information Array
/columns/name Column name string
/columns/type JSON Data type string
/rows SQL SELECT execution results Array

Example:

Depending on the column data type, column values with the following JSON data type will be returned.

Classification JSON Data type JSON data type Example
Primitive Boolean type BOOL Boolean (true/false) true
String type STRING string "GridDB"
Integer type BYTE/SHORT/INTEGER/LONG Number 512
Floating point type FLOAT/DOUBLE Number 593.5
Date and time type TIMESTAMP Text string
・UTC
・format
YYYY-MM-DDThh:mm:ss.SSSZ
"2016-01-16T10:25:00.253Z"

[Memo]

  • In case that column value is NULL, null will be returned for the column in JSON data.
  • BLOB, GEOMETRY and array types are not supported in this function.
  • For BLOB columns, "BLOB" will be returned as data type, and an empty string will be returned as data value in case that the column value is not NULL.
  • For GEOMETRY and array columns, "UNKNOWN" will be returned as data type, and null will be returned as data value.

1.14 Checking of operation

To check the operation of the Web API, use curl command in linux or another command.

  • Example: Confirming database connection

    curl -f -X GET -u ""user: password"" \
    http://host:port/griddb/v2/cluster/dbs/public/checkConnection
    
  • Example: Acquiring a connection list

    curl -f -X GET -u ""user: password"" \
    http://host:port/griddb/v2/cluster/dbs/public/containers?limit=100
    
  • Example) Row acquisition

    curl -X POST -u "user:password" \
    -H "Content-type:application/json; charset=UTF-8" -d '{"limit":5,"sort":"id asc"}' \
    http://host:port/griddb/v2/cluster/dbs/public/containers/test/rows
    
  • Example) Row registration

    curl -X PUT -u "user:password" \
    -H "Content-type:application/json; charset=UTF-8" -d '[[1,"value"],[2,"value"]]' \
    http://host:port/griddb/v2/cluster/dbs/public/containers/test/rows
    
  • Example) SQL SELECT execution

    curl -X POST -u "user:password" \
    -H "Content-type:application/json; charset=UTF-8" -d '{"type":"sql-select","stmt":"select * from test"}' \
    http://host:port/griddb/v2/cluster/dbs/public/sql
    

1.15 Uninstallation

Delete the directory and the distributed files in the following procedures after stopping the Web API.

# rpm -e griddb-ee-webapi