申请抢先体验

请填写名字,以及邮箱或手机号。我们会与您联系,提供 Tajo 访问详情。

第一次 API 调用

下面完成第一次 API 调用,验证你的 Brevo API 配置是否正常工作。

前置条件

  • 一个 Brevo 账号
  • 从仪表板获取的 API 密钥
  • 一个发送 HTTP 请求的工具(curl、Postman 或类似工具)

获取账户信息

最简单的第一次调用是获取账户信息:

使用 cURL

Terminal window
curl -X GET "https://api.brevo.com/v3/account" \
-H "Accept: application/json" \
-H "api-key: YOUR_API_KEY"

使用 JavaScript(Node.js)

const fetch = require('node-fetch');
const getAccount = async () => {
try {
const response = await fetch('https://api.brevo.com/v3/account', {
method: 'GET',
headers: {
'Accept': 'application/json',
'api-key': 'YOUR_API_KEY'
}
});
const data = await response.json();
console.log('Account Info:', data);
} catch (error) {
console.error('Error:', error);
}
};
getAccount();

使用 Python

import requests
url = "https://api.brevo.com/v3/account"
headers = {
"Accept": "application/json",
"api-key": "YOUR_API_KEY"
}
response = requests.get(url, headers=headers)
print(response.json())

使用 PHP

<?php
$url = 'https://api.brevo.com/v3/account';
$headers = [
'Accept: application/json',
'api-key: YOUR_API_KEY'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>

预期响应

调用成功后,你会收到类似下面的响应:

{
"email": "[email protected]",
"firstName": "John",
"lastName": "Doe",
"companyName": "Your Company",
"address": {
"street": "123 Main Street",
"city": "New York",
"zipCode": "10001",
"country": "United States"
},
"plan": [
{
"type": "payAsYouGo",
"credits": 10000,
"creditsUsed": 1500
}
]
}

错误处理

如果遇到错误,请排查以下常见问题:

API 密钥无效(401 Unauthorized)

{
"code": "unauthorized",
"message": "Invalid API key provided"
}

解决办法:确认 API 密钥正确,且具备所需权限。

超出速率限制(429 Too Many Requests)

{
"code": "too_many_requests",
"message": "Rate limit exceeded"
}

解决办法:等待一段时间再发起请求,或升级你的套餐。

服务器错误(500 Internal Server Error)

{
"code": "internal_error",
"message": "An internal error occurred"
}

解决办法:查看 状态页面 或联系支持团队。

后续步骤

第一次 API 调用成功之后,接下来可以:

  1. 正确地 设置身份验证
  2. 为你使用的语言 安装 SDK
  3. 了解速率限制
  4. 查看邮件相关端点

申请抢先体验

请填写名字,以及邮箱或手机号。我们会与您联系,提供 Tajo 访问详情。

自动识别
AI 助手

你好!关于文档有任何问题都可以问我。