Efficiency Unleashed: Streamlining Workflows with the InfluxDB Management API
By
Jessica Wachtel /
Developer
May 23, 2024
Navigate to:
InfluxDB recently launched the InfluxDB Management API for InfluxDB Cloud Dedicated. Now, developers can manage databases, database tokens, and create database tables with custom partitioning directly from their application. The Management API provides a programmatic interface for performing tasks that previously required human interaction.
This interface promotes easier workflows for applications that need automatic provisioning of multiple instances of InfluxDB, either for internal or external purposes. Developers can also include database management in their own code and applications through integrated functions, boosting automation, speed, and efficiency.
Previously, the only way to provision database services was through the influxctl
CLI. This option is still available and unchanged. The Management API simply offers a second option for developers who need automation.
How it works
Similar to provisioning database services through influxctl
CLI, the Management API requires a management token. Unlike database tokens, management tokens regulate databases, tables, and access tokens in your cluster. Their purpose does not extend to reading or writing data.
InfluxDB v3’s management tokens are short-lived by default. The OAuth2 identity provider grants a specific user administrative access to your InfluxDB cluster. For automation purposes, developers can now create long-lasting management tokens that bypass the OAuth identity provider and authenticate directly with their InfluxDB cluster. The long-lasting tokens work with the Management API and automation workflow because they don’t require human interaction. Use the influxctl
CLI to create long-lasting management tokens.
You can access the Management API endpoints for your cluster at:
https://console.influxdata.com/api/v0/accounts/{accountId}/clusters/{clusterId}
Manage databases
Create, list, update, and delete databases in your Cloud Dedicated cluster at the following endpoint:
/api/v0/accounts/{accountId}/clusters/{clusterId}/databases
Example: create a database
curl \
--location "https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/databases" \
--request POST
--header "Accept: application/json" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer MANAGEMENT_TOKEN" \
--data '{
"name": "'DATABASE_NAME'",
"maxTables": 500,
"maxColumnsPerTable": 250,
"retentionPeriod": 2592000000000,
"partitionTemplate": [
{
"type": "tag",
"value": "TAG_KEY_1"
},
{
"type": "tag",
"value": "TAG_KEY_2"
},
{
"type": "bucket",
"value": {
"tagName": "TAG_KEY_3",
"numberOfBuckets": 100
}
},
{
"type": "bucket",
"value": {
"tagName": "TAG_KEY_4",
"numberOfBuckets": 300
}
},
{
"type": "time",
"value": "%Y-%m-%d"
}
]
}'
InfluxDB Cloud Dedicated customers can customize partitions. A partition is a logical grouping of data stored in Apache Parquet format in InfluxDB v3. By default, InfluxDB Cloud Dedicated partitions data by day. Developers can customize their partition strategy to improve query performance if the default mode isn’t optimal for their schema and workload.
Database tokens
Database tokens grant read and write permissions to one or more databases in your cluster. After a developer generates the database token, they are dispersible between applications, devices, and customers. To authenticate an application, the database token and database name is included in each write or query request to a cluster.
Create, list, update, and delete database tokens in your Cloud Dedicated cluster at the following endpoint:
/api/v0/accounts/{accountId}/clusters/{clusterId}/tokens
Each device requires a unique token to write and query data stored in one or more cluster databases. Database token rotation is a security best practice and common workflow. This includes creating and assigning new tokens and deleting old tokens on a schedule.
Example: create and delete tokens
sh
curl \
--location "https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/tokens" \
--header "Accept: application/json" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer MANAGEMENT_TOKEN" \
--data '{
"description": "Read/write token for DATABASE_NAME",
"permissions": [
{
"action": "write",
"resource": "DATABASE_NAME"
},
{
"action": "read",
"resource": "DATABASE_NAME"
}
]
}'
To learn more about the InfluxDB Management API, check out our documentation. To learn more about Cloud Dedicated’s performance, please see our benchmarking paper or contact our sales team for further assistance.