REST Client Access to the DBaaS API
This page is part of MariaDB's Documentation.
The parent of this page is: MariaDB SkySQL DBaaS API
Topics on this page:
Overview
SkySQL operations can be automated using the MariaDB SkySQL DBaaS API.
A REST Client is one way to access the SkySQL DBaaS API.
Any REST client can be used. The examples on this page use cURL.
The examples on this page demonstrate common service management operations. For a full list of supported REST API endpoints, see "SkySQL API Reference".
The MariaDB SkySQL DBaaS API is a Technical Preview. Software in Tech Preview should not be used for production workloads.
Use Cases
Scripting or automating the creation or deletion of SkySQL services
Retrieving the default database credentials for a SkySQL service
Updating the IP allowlist for a SkySQL service
Compatibility
Distributed Transactions
Multi-Node Analytics
Replicated Transactions
Single Node Analytics
Single Node Transactions
Authentication and Authorization
The MariaDB SkySQL DBaaS API requires authentication and authorization.
To authenticate and authorize with the API:
Obtain a SkySQL API Key with
SkySQL API: Databases
scopeUse the bearer token to authenticate for API requests:
The
Authorization
header must be in the formatAuthorization: Bearer SKYSQL_BEARER_TOKEN
, whereSKYSQL_BEARER_TOKEN
is the bearer tokenThe endpoint depends on the specific API request.
Retrieving Service Information
The following examples retrieve information about SkySQL services.
These types of operations are commonly automated to confirm service configuration, prepare for other REST API calls, and to confirm service readiness to receive traffic.
Services List
Similar to the "Your Services" list in the SkySQL Portal, you can retrieve the list of all active services you (or your SkySQL Team) have created.
Detail | Description |
---|---|
Endpoint | https://api.skysql.net/services/
|
Method |
|
Behavior |
|
Parameters |
|
Response Code |
|
API References | |
Sample Request | https://api.skysql.net/services/
|
Command-Line Example | $ curl --location \
--header 'Authorization: Bearer SKYSQL_BEARER_TOKEN' \
https://api.skysql.net/services/ \
| jq .
|
Retrieve Service ID by Service Name
REST API calls related to specific services require that the Service ID be specified. The Service ID can be looked-up from the Service Name.
Detail | Description |
---|---|
Endpoint | https://api.skysql.net/services/
|
Method |
|
Behavior |
|
Parameters |
|
Response Code |
|
API References | |
Sample Request | https://api.skysql.net/services/?name=doc-test-tx-single
|
Command-Line Example | $ curl --location \
--header 'Authorization: Bearer SKYSQL_BEARER_TOKEN' \
https://api.skysql.net/services/?name=doc-test-tx-single \
| jq '{ "name": .[0].name, "id": .[0].id }'
|
Sample Response | {
"name": "doc-test-tx-single",
"id": "db00000001"
}
|
Service Status
Service status indicates when a new service is ready to receive connections.
Detail | Description |
---|---|
Endpoint | https://api.skysql.net/services/SERVICE_ID/status/
|
Method |
|
Behavior |
|
Parameters |
|
Response Code |
|
API References | |
Sample Request | https://api.skysql.net/services/db00000001/status/
|
Command-Line Example | For a Service ID of $ curl --location \
--header 'Authorization: Bearer SKYSQL_BEARER_TOKEN' \
https://api.skysql.net/services/db00000001/status/ \
| jq .
|
Sample Response | {
"status": "Running"
}
|
Creating a Service
The following examples cover activities commonly performed when creating a new SkySQL service.
The use of automation to create services helps ensure repeatability and the correct creation of services of the desired specification.
Create a Database Service
SkySQL enables creation of services with multiple cloud providers and regions, customized to your specifications.
Detail | Description |
---|---|
Endpoint | https://api.skysql.net/services/
|
Method |
|
Content Type |
|
Behavior |
|
Request Body |
|
Response Code |
|
API References | |
Sample Request Body | {
"name": "doc-test-tx-single",
"provider": "AWS",
"region": "us-east-2",
"release_version": "MariaDB Enterprise Server 10.6.4-1",
"replicas": "0",
"size": "Sky-2x8",
"tier": "Foundation",
"topology": "Single Node Transactions",
"tx_storage": "100",
"volume_iops": "100"
}
|
Sample Request | https://api.skysql.net/services/
|
Command-Line Example | With the request body saved to $ curl --location --request POST \
--header 'Authorization: Bearer SKYSQL_BEARER_TOKEN' \
--header 'Content-type: application/json' \
--data '@request.json' \
https://api.skysql.net/services/ \
| jq .
|
Add IP Address to Allowlist
By default, access to SkySQL services is blocked by a firewall. An IP allowlist specifies which IP addresses are permitted to connect to the service.
Detail | Description |
---|---|
Endpoint | https://api.skysql.net/services/SERVICE_ID/security/allowlist/
|
Method |
|
Content Type |
|
Behavior |
|
Request Body |
|
Response Code |
|
API References | |
Sample Request Body | {
"ip_address": "CLIENT_IP_ADDRESS/SUBNET_MASK"
}
|
Sample Request | For a Service ID of https://api.skysql.net/services/db00000001/security/allowlist/
|
Command-Line Example | With the request body saved to $ curl --location --request POST \
--header 'Authorization: Bearer SKYSQL_BEARER_TOKEN' \
--header 'Content-type: application/json' \
--data '@request.json' \
https://api.skysql.net/services/db00000001/security/allowlist/ \
| jq .
To check the status of this operation: $ curl --location \
--header 'Authorization: Bearer SKYSQL_BEARER_TOKEN' \
https://api.skysql.net/services/db00000001/security/allowlist/status/ \
| jq .
|
Sample Request | {
"status": "Enforcing"
}
|
Obtain Database Credentials
Default credentials are set at time of service creation.
Detail | Description |
---|---|
Endpoint | https://api.skysql.net/services/SERVICE_ID/security/credentials/
|
Method |
|
Behavior |
|
Parameters |
|
Response Code |
|
API References | |
Sample Request | For a Service ID of https://api.skysql.net/services/db00000001/security/credentials/
|
Command-Line Example | $ curl --location \
--header 'Authorization: Bearer SKYSQL_BEARER_TOKEN' \
https://api.skysql.net/services/db00000001/security/credentials/ \
| jq .
|
Sample Output | {
"username": "DB00000001",
"password": "SKYSQL_DEFAULT_PASSWORD"
}
|
Obtain Service Connection Details
Service details are used to connect to the database service.
Detail | Description |
---|---|
Endpoint | https://api.skysql.net/services/SERVICE_ID/
|
Method |
|
Behavior |
|
Parameters |
|
Response Code |
|
API References | |
Sample Request | For a Service ID of https://api.skysql.net/services/db00000001/
|
Command-Line Example | For a Service ID of curl --location \
--header 'Authorization: Bearer SKYSQL_BEARER_TOKEN' \
https://api.skysql.net/services/db00000001/ \
| jq '{ "provider": .provider, "host": .fqdn, "read_only_port": .read_only_port, "read_write_port": .read_write_port, "ssl_tls": .ssl_tls }'
|
Sample Output | {
"provider": "Amazon AWS",
"host": "doc-test-tx-single-gcp.mdb0100087.stage.skysql.net",
"read_only_port": "",
"read_write_port": "5001",
"ssl_tls": "Enabled"
}
|
Using the Service
After creating a SkySQL service, it is typical to:
Perform testing, such as with sample applications
Deleting a Service
Deletion is non-reversible. Deletion removes the service and all data in the service. Charges for a service stop accruing when the service is deleted.
Ephemeral environments (such as Continuous Integration and testing) are commonly deleted when no longer needed.
Production environments are rarely deleted. Before deleting a service, consider whether production workloads are present.
Detail | Description |
---|---|
Endpoint | https://api.skysql.net/services/SERVICE_ID/status/
|
Method |
|
Behavior |
|
Parameters |
|
Response Code |
|
API References | |
Sample Request | For a Service ID of https://api.skysql.net/services/db00000001/
|
Command-Line Example | For a Service ID of $ curl --location --request DELETE \
--header 'Authorization: Bearer SKYSQL_BEARER_TOKEN' \
https://api.skysql.net/services/db00000001/ \
| jq .
|
Shell Scripting
curl is a command-line HTTP/HTTPS client.
jq is a command-line JSON processor.
curl
and jq
can be used together in shell scripts to interact with a REST API. For example:
#!/bin/env bash
SKYSQL_API_KEY='...'
SKYSQL_AUTH_RESPONSE="$(curl -sS --location --request POST \
--header "Authorization: Token $SKYSQL_API_KEY" \
--header 'Content-length: 0' \
https://id.mariadb.com/api/v1/token/)"
if [[ "$SKYSQL_AUTH_RESPONSE" == *entitlements* ]]; then
SKYSQL_BEARER_TOKEN="$(echo "$SKYSQL_AUTH_RESPONSE" | jq -r .token)"
else
echo "Failed to authenticate with API key:"
echo "$SKYSQL_AUTH_RESPONSE"
exit 1
fi
SKYSQL_SERVICES_RESPONSE="$(curl -sS --location \
--header "Authorization: Bearer $SKYSQL_BEARER_TOKEN" \
https://api.skysql.net/services/)"
if [[ "$SKYSQL_SERVICES_RESPONSE" == '['* ]]; then
(echo "Current services:"
echo "$SKYSQL_SERVICES_RESPONSE" | jq .
) | less
else
echo "Failed to get list of services:"
echo "$SKYSQL_SERVICES_RESPONSE"
exit 1
fi
Troubleshooting
Invalid token
Cause | An invalid SkySQL API key is provided when requesting a bearer token. |
Effect | Authentication fails and an error is returned. |
Solution | |
Example Error | {
"detail": "Invalid token."
}
|
JWT is invalid
JWT is short for "JSON Web Token".
Cause | An invalid or expired bearer token is provided when sending an API request. |
Effect | Authentication fails and an error is returned. |
Solution | |
Example Error | {
"detail": "JWT is invalid"
}
|
Setup incomplete
Cause | An API request is sent when account billing details are incomplete. |
Effect | The API request fails with an error. |
Solution | |
Example Error | {
"detail": "Setup incomplete, missing billing and/or default project"
}
|