InfluxDB API快速入门
InfluxDB API快速入门

InfluxDB提供了丰富的API和客户端库,可以与您的应用程序集成。使用流行的工具如Curl和Postman快速测试API请求。

本节将指导您了解最常用的API方法。

有关整个API的详细文档,请参阅InfluxDBv2 API参考。

如果您需要将InfluxDB 2.7与InfluxDB 1.x API客户端和集成一起使用,请参阅1.x兼容性API。

引导应用程序

对于大多数API请求,您需要提供最少的InfluxDB URL和授权令牌(API令牌)。

安装InfluxDB OSS v2.x或升级到 InfluxDB Cloud账户

认证

InfluxDB使用API令牌来授权API请求。

  1. 在探索API之前,请使用InfluxDB UI 为应用程序创建初始API令牌。
  2. 在每个请求的Authorization: Token YOUR_API_TOKEN HTTP头中包含您的API令牌。

卷曲 Node.js

####################################### # Use a token in the Authorization header # to authenticate with the InfluxDB 2.x API. #######################################  curl --get "http://localhost:8086/api/v2" \   --header "Authorization: Token YOUR_API_TOKEN" \   --header 'Content-type: application/json' \   --data-urlencode "db=mydb" \   --data-urlencode "q=SELECT * FROM cpu_usage" 

更改InfluxDB URL

Postman是另一个用于探索API的流行工具。查看如何使用Postman发送经过身份验证的请求。

Buckets API

在写入数据之前,您需要在InfluxDB中创建一个Bucket。 使用对InfluxDB API /buckets端点的HTTP请求创建一个存储桶。

INFLUX_TOKEN=YOUR_API_TOKEN INFLUX_ORG_ID=YOUR_ORG_ID  curl --request POST \   "http://localhost:8086/api/v2/buckets" \   --header "Authorization: Token ${INFLUX_TOKEN}" \   --header "Content-type: application/json" \   --data '{     "orgID": "'"${INFLUX_ORG_ID}"'",     "name": "iot-center",     "retentionRules": [       {         "type": "expire",         "everySeconds": 86400,         "shardGroupDurationSeconds": 0       }     ]   }' 

更改InfluxDB URL

编写API

使用对InfluxDB API /api/v2/write端点的HTTP请求将数据写入InfluxDB。

查询API

使用HTTP请求从InfluxDB查询/api/v2/query端点。

我的微信