APIチャネルにメッセージを送信する方法
API Channel は暗黙的なコンタクト作成をサポートしていないため、Livedesk では API Channel を次の 3 つの手順で使用します。
- コンタクトを作成する
- コンタクト情報に基づいて会話を作成する
- メッセージを送信する
コンタクトを作成する
API エンドポイント
https://livedesk-api.engagelab.com/api/v2/accounts/contacts
リクエスト例
curl -X POST https://livedesk-api.engagelab.com/api/v2/accounts/contacts \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
-d '{
"inbox_id": 407,
"name": "Test",
"email": "alice@acme.inc",
"phone_number": "+123456789",
"avatar_url": "https://example.com/avatar.png",
"identifier": "1234567890"
}'
curl -X POST https://livedesk-api.engagelab.com/api/v2/accounts/contacts \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
-d '{
"inbox_id": 407,
"name": "Test",
"email": "alice@acme.inc",
"phone_number": "+123456789",
"avatar_url": "https://example.com/avatar.png",
"identifier": "1234567890"
}'
このコードブロックはフローティングウィンドウ内に表示されます
リクエストヘッダー
| Field | Type | Description |
|---|---|---|
| Authorization | string | 認証には Authorization: Basic base64(API Key:API Secret) を使用します。API Key ページで API Key と API Secret を取得し、Base64 エンコードする前にコロン(:)で連結してください。 |
| Content-Type | application/json | データ形式。プレーンテキストメッセージには application/json を使用します。 |
リクエストボディパラメータ
| Field | Type | Required | Description |
|---|---|---|---|
| inbox_id | String | Yes | チャネル ID。「Project Settings > Channels > Specific channel > Settings」の Channel ID に対応します。 |
| name | String | No | コンタクト名。 |
| String | No | メールアドレス。 | |
| phone_number | String | No | 電話番号。 |
| avatar_url | String | No | アバター URL。 |
| identifier | String | No | ユーザー識別子。 |
レスポンス例
{
"payload": {
"contact": {
"additional_attributes": {},
"availability_status": "offline",
"email": null,
"id": 2219259,
"name": "Test",
"phone_number": null,
"blocked": false,
"identifier": null,
"thumbnail": "",
"custom_attributes": {},
"created_at": 1766571703,
"contact_inboxes": []
},
"contact_inbox": {
"inbox": null,
"source_id": null
}
}
}
{
"payload": {
"contact": {
"additional_attributes": {},
"availability_status": "offline",
"email": null,
"id": 2219259,
"name": "Test",
"phone_number": null,
"blocked": false,
"identifier": null,
"thumbnail": "",
"custom_attributes": {},
"created_at": 1766571703,
"contact_inboxes": []
},
"contact_inbox": {
"inbox": null,
"source_id": null
}
}
}
このコードブロックはフローティングウィンドウ内に表示されます
レスポンスパラメータ
| Field | Type | Required | Description |
|---|---|---|---|
| additional_attributes | Object | No | 追加属性。 |
| availability_status | String | No | ステータス。デフォルトは offline です。 |
| String | No | メールアドレス。 | |
| id | String | No | コンタクト ID。 |
| name | String | No | 名前。 |
| phone_number | String | No | 電話番号。 |
| blocked | String | No | ブロックされているかどうか。デフォルトは false です。 |
| identifier | String | No | ユーザー識別子。 |
| thumbnail | String | No | サムネイル。 |
| custom_attributes | String | No | 顧客属性。 |
| created_at | String | No | 作成タイムスタンプ。 |
| contact_inboxes | Array | No | コンタクトの受信箱一覧。 |
| inbox | String | No | チャネル情報。 |
| source_id | String | No | ソース ID。 |
会話を作成する
API エンドポイント
https://livedesk-api.engagelab.com/api/v2/accounts/conversations
リクエスト例
curl -X POST https://livedesk-api.engagelab.com/api/v2/accounts/conversations \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
-d '{
"inbox_id": 407,
"contact_id": 2219256,
"source_id": "123456789"
}'
curl -X POST https://livedesk-api.engagelab.com/api/v2/accounts/conversations \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
-d '{
"inbox_id": 407,
"contact_id": 2219256,
"source_id": "123456789"
}'
このコードブロックはフローティングウィンドウ内に表示されます
リクエストヘッダー
| Field | Type | Description |
|---|---|---|
| Authorization | string | 認証には Authorization: Basic base64(API Key:API Secret) を使用します。API Key ページで API Key と API Secret を取得し、Base64 エンコードする前にコロン(:)で連結してください。 |
| Content-Type | application/json | データ形式。プレーンテキストメッセージには application/json を使用します。 |
リクエストボディパラメータ
| Field | Type | Required | Description |
|---|---|---|---|
| inbox_id | String | Yes | チャネル ID。コンタクト作成 API で使用した ID と同じです。 |
| contact_id | String | No | コンタクト ID。コンタクト作成 API のレスポンスに含まれる id です。 |
| source_id | String | No | ソース ID。contact_id または source_id のいずれかを渡せますが、送信者を正しく識別できる必要があります。 |
レスポンス例
{
"meta": {
"sender": {
"additional_attributes": {},
"availability_status": "offline",
"email": null,
"id": 2219256,
"name": "Test",
"phone_number": null,
"blocked": false,
"identifier": null,
"thumbnail": "",
"custom_attributes": {},
"created_at": 1766571624
},
"channel": "Channel::Api",
"hmac_verified": false
},
"id": 40,
"messages": [],
"account_id": 17623000010928,
"uuid": "660ce36f-46bb-4153-948c-8a26e6dab634",
"inbox_id": 407,
"additional_attributes": {},
"agent_last_seen_at": 0,
"assignee_last_seen_at": 0,
"can_reply": true,
"contact_last_seen_at": 0,
"custom_attributes": {},
"labels": [],
"muted": false,
"snoozed_until": null,
"status": "open",
"priority": null,
"conversation_category": "chat",
"chat_mode": "private_chat",
"is_forum": false,
"created_at": 1766572062,
"updated_at": 1766572062.5803902,
"timestamp": 1766572062,
"first_reply_created_at": 0,
"unread_count": 0,
"last_non_activity_message": null,
"last_activity_at": 1766572062,
"waiting_since": 1766572062,
"sla_policy_id": null,
"ticket_id": null,
"over_limit": false,
"content_preview": {
"content": null,
"message_type": null,
"created_at": null
},
"platform": {
"channel_type": "Channel::Api",
"inbox_name": "JennyApi",
"inbox_id": 407
},
"account_info": {
"contact_name": "Test",
"contact_email": null,
"contact_phone": null,
"contact_id": 2219256,
"contact_avatar": ""
},
"assignment": {
"assignee_id": null,
"assignee_name": null,
"assignee_email": null,
"team_id": null,
"team_name": null
}
}
{
"meta": {
"sender": {
"additional_attributes": {},
"availability_status": "offline",
"email": null,
"id": 2219256,
"name": "Test",
"phone_number": null,
"blocked": false,
"identifier": null,
"thumbnail": "",
"custom_attributes": {},
"created_at": 1766571624
},
"channel": "Channel::Api",
"hmac_verified": false
},
"id": 40,
"messages": [],
"account_id": 17623000010928,
"uuid": "660ce36f-46bb-4153-948c-8a26e6dab634",
"inbox_id": 407,
"additional_attributes": {},
"agent_last_seen_at": 0,
"assignee_last_seen_at": 0,
"can_reply": true,
"contact_last_seen_at": 0,
"custom_attributes": {},
"labels": [],
"muted": false,
"snoozed_until": null,
"status": "open",
"priority": null,
"conversation_category": "chat",
"chat_mode": "private_chat",
"is_forum": false,
"created_at": 1766572062,
"updated_at": 1766572062.5803902,
"timestamp": 1766572062,
"first_reply_created_at": 0,
"unread_count": 0,
"last_non_activity_message": null,
"last_activity_at": 1766572062,
"waiting_since": 1766572062,
"sla_policy_id": null,
"ticket_id": null,
"over_limit": false,
"content_preview": {
"content": null,
"message_type": null,
"created_at": null
},
"platform": {
"channel_type": "Channel::Api",
"inbox_name": "JennyApi",
"inbox_id": 407
},
"account_info": {
"contact_name": "Test",
"contact_email": null,
"contact_phone": null,
"contact_id": 2219256,
"contact_avatar": ""
},
"assignment": {
"assignee_id": null,
"assignee_name": null,
"assignee_email": null,
"team_id": null,
"team_name": null
}
}
このコードブロックはフローティングウィンドウ内に表示されます
レスポンスパラメータ
| Field | Type | Required | Description |
|---|---|---|---|
| meta | Object | No | メタデータオブジェクト。 |
| meta.sender | Object | No | 送信者情報。 |
| meta.sender.additional_attributes | Object | No | 追加属性。 |
| meta.sender.availability_status | String | No | 利用可能状態。 |
| meta.sender.email | Null | No | メールアドレス。 |
| meta.sender.id | Number | No | コンタクト ID。 |
| meta.sender.name | String | No | 送信者名。 |
| meta.sender.phone_number | Null | No | 電話番号。 |
| meta.sender.blocked | Boolean | No | ブロックされているかどうか。 |
| meta.sender.identifier | Null | No | ユーザー識別子。 |
| meta.sender.thumbnail | String | No | サムネイル。 |
| meta.sender.custom_attributes | Object | No | カスタム属性。 |
| meta.sender.created_at | Number | No | 作成タイムスタンプ。 |
| meta.channel | String | No | チャネルタイプ。 |
| meta.hmac_verified | Boolean | No | HMAC 検証ステータス。 |
| id | Number | No | 会話 ID。 |
| messages | Array | No | メッセージ配列。 |
| account_id | Number | No | プロジェクト ID。 |
| uuid | String | No | 一意の識別子。 |
| inbox_id | Number | No | チャネル ID。 |
| additional_attributes | Object | No | 追加属性。 |
| agent_last_seen_at | Number | No | エージェントが最後に確認した時刻。 |
| assignee_last_seen_at | Number | No | 担当者が最後に確認した時刻。 |
| can_reply | Boolean | No | 返信可能かどうか。 |
| contact_last_seen_at | Number | No | コンタクトが最後に確認した時刻。 |
| custom_attributes | Object | No | カスタム属性。 |
| labels | Array | No | ラベル配列。 |
| muted | Boolean | No | ミュートされているかどうか。 |
| snoozed_until | Null | No | スヌーズ終了時刻。 |
| status | String | No | ステータス。 |
| priority | Null | No | 優先度。 |
| conversation_category | String | No | 会話カテゴリ。 |
| chat_mode | String | No | チャットモード。 |
| is_forum | Boolean | No | フォーラムかどうか。 |
| created_at | Number | No | 作成タイムスタンプ。 |
| updated_at | Number | No | 更新タイムスタンプ。 |
| timestamp | Number | No | タイムスタンプ。 |
| first_reply_created_at | Number | No | 最初の返信の作成時刻。 |
| unread_count | Number | No | 未読件数。 |
| last_non_activity_message | Null | No | 最後の非アクティビティメッセージ。 |
| last_activity_at | Number | No | 最終アクティビティ時刻。 |
| waiting_since | Number | No | 待機開始時刻。 |
| sla_policy_id | Null | No | SLA ポリシー ID。 |
| ticket_id | Null | No | チケット ID。 |
| over_limit | Boolean | No | 上限を超えているかどうか。 |
| content_preview | Object | No | コンテンツプレビュー。 |
| content_preview.content | Null | No | プレビュー内容。 |
| content_preview.message_type | Null | No | メッセージタイプ。 |
| content_preview.created_at | Null | No | 作成時刻。 |
| platform | Object | No | プラットフォーム情報。 |
| platform.channel_type | String | No | チャネルタイプ。 |
| platform.inbox_name | String | No | 受信箱名。 |
| platform.inbox_id | Number | No | 受信箱 ID。 |
| account_info | Object | No | アカウント情報。 |
| account_info.contact_name | String | No | コンタクト名。 |
| account_info.contact_email | Null | No | コンタクトのメールアドレス。 |
| account_info.contact_phone | Null | No | コンタクトの電話番号。 |
| account_info.contact_id | Number | No | コンタクト ID。 |
| account_info.contact_avatar | String | No | コンタクトのアバター。 |
| assignment | Object | No | 割り当て情報。 |
| assignment.assignee_id | Null | No | 担当者 ID。 |
| assignment.assignee_name | Null | No | 担当者名。 |
| assignment.assignee_email | Null | No | 担当者メールアドレス。 |
| assignment.team_id | Null | No | チーム ID。 |
| assignment.team_name | Null | No | チーム名。 |
メッセージを送信する
API エンドポイント
https://livedesk-api.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages
リクエスト例
curl -X POST 'https://livedesk-api.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages' \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
-d '{
"content": "カスタマーサービスがメッセージを送信しましたが、正常ですか?",
"private": false,
"message_type": "incoming",
"content_attributes": {
"in_reply_to": 29
}
}'
curl -X POST 'https://livedesk-api.engagelab.com/api/v2/accounts/conversations/:conversation_id/messages' \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic base64(api_key:api_secret)' \
-d '{
"content": "カスタマーサービスがメッセージを送信しましたが、正常ですか?",
"private": false,
"message_type": "incoming",
"content_attributes": {
"in_reply_to": 29
}
}'
このコードブロックはフローティングウィンドウ内に表示されます
リクエストヘッダー
| Field | Type | Description |
|---|---|---|
| Authorization | string | 認証には Authorization: Basic base64(API Key:API Secret) を使用します。API Key ページで API Key と API Secret を取得し、Base64 エンコードする前にコロン(:)で連結してください。 |
| Content-Type | application/json | データ形式。プレーンテキストメッセージには application/json を使用します。 |
リクエストボディパラメータ
| Field | Type | Required | Description |
|---|---|---|---|
| content | String | No | メッセージ本文。 |
| private | String | No | プライベートメッセージかどうか。 |
| message_type | String | No | メッセージタイプ。outgoing または incoming を指定します。それぞれカスタマーサービスからの送信、またはユーザーからの送信を表します。指定しない場合、デフォルトは outgoing です。 |
| content_attributes | String | No | コンテンツ属性。 |
| content_attributes.in_reply_to | String | No | 返信先メッセージ ID。 |










