認証
このセクションでは、Mico Voice AI API での認証方法について説明します。
ステップ 1: Mico Voice AI からクライアント ID とシークレットを取得する
- micovoice.com にログインします。
- サイドバーの “組織” をクリックします。
- “外部連携” タブをクリックします。
- “API 連携” セクションまでスクロールします。
- “APIアクセス認証情報” 下の "認証情報を生成する” をクリックします。
- 次のステップで必要になるため、クライアント ID とシークレットを控えておいてください。
ステップ 2: アクセストークンを取得する
クライアントアプリケーションから API サーバーのトークンエンドポイントに対して POST リクエストを送信し、アクセストークンを取得する必要があります。
リクエスト詳細:
- メソッド:
POST - URL:
https://api.micovoice.com/oauth/token - ヘッダー:
Content-Type: application/x-www-form-urlencoded
- ボディ:
grant_type=client_credentialsclient_id=<your_client_id>client_secret=<your_client_secret>scope="campaigns:write campaigns:read calls:write calls:read"
リクエスト詳細:
access_token レスポンスが返され、API 内のリソースへのアクセスが可能になります。
レスポンスの例:
{
"access_token": "nzoPXvZLrEGuXRbxNfg9zAYUwTkiKHHxrAyFivypDELLtuJEqdDCTr9hVEfTcUXiky9LZGMsDAtxilHBXMUVJS",
"expires_in": 86399,
"token_type": "bearer"
}
curl を使った例:
curl -X POST https://api.micovoice.com/oauth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "client_id=YOUR_CLIENT_ID" \
--data-urlencode "client_secret=YOUR_CLIENT_SECRET" \
--data-urlencode "scope=calls:read campaigns:read campaigns:write calls:write"
Javascript を使った例
const params = new URLSearchParams();
params.append("grant_type", "client_credentials");
params.append("client_id", "YOUR_CLIENT_ID");
params.append("client_secret", "YOUR_CLIENT_SECRET");
params.append("scope", "calls:write calls:read");
const response = await fetch("https://api.micovoice.com/oauth/token", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: params,
});
const data = await response.json();
const token = data.access_token;
ステップ 3: アクセストークンを使用する
access_token を API リクエストの認証ヘッダーに含めます:
ヘッダー:
Authorization: Bearer <access_token>
curl を使った例:
curl -X GET https://api.micovoice.com/v1/outbound_calls/${callUid} \
-H "Authorization: Bearer eyJhbGciOi...example-token..."
javascript を使った例:
const callUid = "your-call-uid";
const accessToken = "eyJhbGciOi...example-token...";
fetch(`https://api.micovoice.com/v1/outbound_calls/${callUid}`, {
method: "GET",
headers: {
Authorization: `Bearer ${accessToken}`,
Accept: "application/json",
},
})
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then((data) => {
console.log("API Response:", data);
})
.catch((error) => {
console.error("Fetch error:", error);
});