You can use cURL commands to create and manage a cloud account with the CURL HTTP client.

Create a database

The API operation that creates a database is: POST /subscriptions/{subscription-id}/databases

The database is created in an existing or a newly created subscription. When a subscription is created, it is created with at least one database. You can add more databases to the subscription, and you can update or delete existing databases.

Creating a database is an asynchronous operation.

The following Linux shell script sends a POST /subscriptions/{subscription-id}/databases and waits for a cloud account ID. When the cloud account ID is received, the processing phase is complete and the provisioning phase starts.

Prerequisites

  • Install jq on your machine: sudo apt install jq

  • Define the expected variables needed to use the API:

    
    

export HOST=api.redislabs.com/v1 export ACCOUNT_KEY={replace-with-your-account-key} export SECRET_KEY={replace-with-your-secret-key} export SUBSCRIPTION_ID={subscription-id} ```

Database JSON body

The created database is defined by a JSON document that is sent as the body of the API request.

In the example below, that JSON document is stored in the create-database-basic.json file:


{
  "name": "Database-example-basic",
  "memoryLimitInGb": 10,
  "password": "P@ssw0rd"
}

The JSON body contains only the most basic, required parameters in order to create a database:

  • Database name - A unique name per subscription that can contain only alphanumeric characters and hyphens
  • Maximum database size in GB
  • Database password

Database creation script

You can run the create database script from the command line with: bash path/script-name.sh

Below is the sample script that you can use as a reference to call the API operation to create a database.


curl -s -X POST "https://$HOST/subscriptions/$SUBSCRIPTION_ID/databases" \
    --header "Content-Type: application/json" \
    -H "accept: application/json" \
    -H "x-api-key: $ACCOUNT_KEY" \
    -H "x-api-secret-key: $SECRET_KEY" \
    --data-binary "@./static/code/rv/api/create-database-basic.json" \
    | jq -r . 

Additional database parameters

There are many additional parameters and settings that can be defined on database creation:

  • Review the database parameters and options in the Swagger OpenAPI documentation.
  • Select POST Create database.
  • Under Database definition, click on the Model options.

swagger-database-create-documentation