퀵스타트
몇 분 만에 처음부터 첫 번째 인증된 호출까지 진행하세요.
1. API 키 생성
앱에서 Settings -> Integrations -> API를 열고 통합에 필요한 가장 작은 스코프 집합(예: items:read)으로 테넌트 API 키를 생성합니다. 전체 비밀 키(pk_live_... 또는 pk_test_...)는 한 번만 표시되므로, 서버 측 시크릿 매니저나 배포 환경에 저장하고 클라이언트 코드나 버전 관리에는 절대 저장하지 마세요.
2. 첫 번째 호출 수행
curl https://api.fabhub.app/v1 \
-H "X-API-Key: $FABHUB_API_KEY"
GET /v1은 자격 증명이 접근할 수 있는 기능을 반환합니다. 자격 증명 자체(스코프, 플랜, 속도 제한 등급)를 검사하려면 GET /v1/auth/context를 호출하세요:
curl https://api.fabhub.app/v1/auth/context \
-H "X-API-Key: $FABHUB_API_KEY"
{
"data": {
"tenant": { "id": "0e2b...c1", "plan": "pro" },
"api_key": {
"id": "key_8f...",
"prefix": "pk_live_8f3a",
"environment": "production",
"scopes": ["items:read", "items:write", "webhooks:write"],
"rate_limit_tier": "standard",
"expires_at": null
}
}
}
3. SDK 설치
npm install @fabhub/sdk
import { FabHubClient } from '@fabhub/sdk';
const fabhub = new FabHubClient({ apiKey: process.env.FABHUB_API_KEY });
// List the first page of items
const items = await fabhub.listItems({ pageSize: 20 });
console.log(items.data.length, 'of', items.pagination.total);
// Read your organization
const { data: organization } = await fabhub.getOrganization();
console.log(organization.name, organization.plan);
4. 무언가 생성하기(멱등성 사용)
쓰기 호출은 Idempotency-Key를 받으므로, 재시도된 요청이 절대 중복을 생성하지 않습니다:
const { data: item } = await fabhub.createItem(
{ name: 'Widget', itemType: 'product', salePrice: 19.99 },
{ idempotencyKey: crypto.randomUUID() },
);
5. 오류 처리
import { FabHubApiError } from '@fabhub/sdk';
try {
await fabhub.listItems();
} catch (err) {
if (err instanceof FabHubApiError) {
console.error(err.status, err.code, err.message);
}
}