첫 API 호출
Brevo API 설정이 올바르게 동작하는지 확인하기 위해 첫 API 호출을 실행해 보겠습니다.
사전 준비 사항
- Brevo 계정
- 대시보드에서 발급받은 API 키
- HTTP 요청을 보낼 수 있는 도구 (curl, Postman 등)
계정 정보 가져오기
가장 간단한 첫 호출은 계정 정보를 가져오는 것입니다.
cURL 사용
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;?>예상 응답
호출에 성공하면 다음과 같은 응답을 받습니다.
{ "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 호출에 성공했다면 다음을 진행합니다.
- 인증 설정하기
- 사용하는 언어에 맞는 SDK 설치하기
- 요청 한도 알아보기
- 이메일 엔드포인트 살펴보기