使用我们的API构建强大的数据处理应用和集成
创建API密钥
在您的DataFlare仪表盘中创建API密钥和密钥对。
获取访问令牌
使用您的API密钥和密钥对获取访问令牌。
调用API端点
使用访问令牌调用任何DataFlare API端点。
使用我们的官方SDK更快地集成DataFlare API
// 安装SDK: npm install dataflare-sdk
import { DataFlareClient } from 'dataflare-sdk';
// 初始化客户端
const client = new DataFlareClient({
apiKey: 'your_api_key',
apiSecret: 'your_api_secret'
});
// 获取SmartModules列表
async function getSmartModules() {
try {
const modules = await client.smartModules.list();
console.log(modules);
} catch (error) {
console.error('获取SmartModules失败:', error);
}
}
// 创建数据流水线
async function createPipeline() {
try {
const pipeline = await client.pipelines.create({
name: '日志处理流水线',
description: '处理应用日志的流水线',
source: {
connector_id: 'conn-5432',
config: {
bucket: 'app-logs',
prefix: 'production/'
}
},
processors: [
{
module_id: 'sm-1234',
config: {
field: 'message',
output_field: 'category'
}
}
],
sink: {
connector_id: 'conn-9876',
config: {
table: 'processed_logs',
batch_size: 100
}
}
});
console.log('流水线已创建:', pipeline);
} catch (error) {
console.error('创建流水线失败:', error);
}
}
getSmartModules();
createPipeline();探索DataFlare API提供的所有端点
curl -X POST https://api.dataflare.dev/v1/auth/token \
-H "Content-Type: application/json" \
-d '{
"api_key": "your_api_key",
"api_secret": "your_api_secret"
}'{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 3600
}curl -X GET https://api.dataflare.dev/v1/smartmodules \
-H "Authorization: Bearer your_access_token"{
"modules": [
{
"id": "sm-1234",
"name": "文本分类器",
"description": "基于机器学习的文本分类模块",
"version": "1.0.0",
"created_at": "2023-10-15T08:30:00Z"
},
{
"id": "sm-5678",
"name": "情感分析",
"description": "分析文本情感倾向的模块",
"version": "2.1.0",
"created_at": "2023-11-20T14:45:00Z"
}
],
"total": 2,
"page": 1,
"page_size": 10
}curl -X GET https://api.dataflare.dev/v1/connectors \
-H "Authorization: Bearer your_access_token"{
"connectors": [
{
"id": "conn-9876",
"name": "PostgreSQL连接器",
"description": "连接PostgreSQL数据库的连接器",
"version": "1.2.0",
"created_at": "2023-09-05T10:20:00Z"
},
{
"id": "conn-5432",
"name": "S3连接器",
"description": "连接Amazon S3存储的连接器",
"version": "1.0.1",
"created_at": "2023-10-12T16:30:00Z"
}
],
"total": 2,
"page": 1,
"page_size": 10
}curl -X POST https://api.dataflare.dev/v1/pipelines \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your_access_token" \
-d '{
"name": "日志处理流水线",
"description": "处理应用日志的流水线",
"source": {
"connector_id": "conn-5432",
"config": {
"bucket": "app-logs",
"prefix": "production/"
}
},
"processors": [
{
"module_id": "sm-1234",
"config": {
"field": "message",
"output_field": "category"
}
}
],
"sink": {
"connector_id": "conn-9876",
"config": {
"table": "processed_logs",
"batch_size": 100
}
}
}'{
"pipeline_id": "pl-7890",
"name": "日志处理流水线",
"status": "created",
"created_at": "2023-12-01T09:15:00Z"
}要获取访问令牌,请向/api/v1/auth/token端点发送POST请求, 包含您的API密钥和密钥对。
Content-Type: application/json
{
"api_key": "your_api_key",
"api_secret": "your_api_secret"
}{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 3600
}访问令牌的有效期为1小时(3600秒)。在令牌过期后,您需要获取新的令牌。
当API请求失败时,您将收到一个包含错误详情的JSON响应,以及相应的HTTP状态码。
{
"error": {
"code": "invalid_credentials",
"message": "提供的API密钥或密钥对无效",
"status": 401
}
}| HTTP状态码 | 错误代码 | 描述 |
|---|---|---|
| 400 | invalid_request | 请求格式无效或缺少必要参数 |
| 401 | invalid_credentials | 认证失败或令牌无效 |
| 403 | forbidden | 没有权限执行请求的操作 |
| 404 | not_found | 请求的资源不存在 |
| 429 | rate_limit_exceeded | 超出API请求速率限制 |
| 500 | server_error | 服务器内部错误 |
为了确保服务质量和公平使用,DataFlare API实施了速率限制。限制根据您的账户类型而有所不同。
| 账户类型 | 限制 |
|---|---|
| 开发者 | 60次请求/分钟 |
| 专业版 | 300次请求/分钟 |
| 企业版 | 1000次请求/分钟 |
当您超出速率限制时,API将返回429状态码和rate_limit_exceeded错误。 响应头中的X-RateLimit-Remaining和X-RateLimit-Reset字段 分别表示剩余的请求次数和重置计数器的时间(以秒为单位)。