> ## Documentation Index
> Fetch the complete documentation index at: https://x-preview-mintlify-5e62557c.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# ダイレクトメッセージの管理

> X API v2 の Manage Direct Messages エンドポイントを使用して、認証済みユーザーの代理で会話の作成、新しい DM の送信、DM イベントの削除を X 上で行います。

export const Button = ({href, children}) => {
  return <div className="not-prose">
    <a href={href}>
      <button className="x-btn">
        <span>{children}</span>
        <svg width="3" height="24" viewBox="0 -9 3 24" class="h-6 rotate-0 overflow-visible"><path d="M0 0L3 3L0 6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"></path></svg>
      </button>
    </a>
  </div>;
};

Manage Direct Messages エンドポイントを使用すると、認証済みユーザーの代理でダイレクトメッセージの送信および削除を行えます。

## 概要

<CardGroup cols={2}>
  <Card title="メッセージ送信" icon="paper-plane">
    他のユーザーに DM を送信
  </Card>

  <Card title="メッセージ削除" icon="trash">
    自分の DM を削除
  </Card>

  <Card title="会話の作成" icon="https://mintcdn.com/x-preview-mintlify-5e62557c/NnGYBQFO1PDkJQK7/icons/xds/icon-chat-unread.svg?fit=max&auto=format&n=NnGYBQFO1PDkJQK7&q=85&s=e8e1b6581e93f23a87dfd20c78b3ef8b" width="24" height="24" data-path="icons/xds/icon-chat-unread.svg">
    新しい会話を開始
  </Card>

  <Card title="グループメッセージ" icon="https://mintcdn.com/x-preview-mintlify-5e62557c/dxXIRy5tzOESXfjK/icons/xds/icon-people.svg?fit=max&auto=format&n=dxXIRy5tzOESXfjK&q=85&s=3df3f471186c3b149f8bf206d86587e3" width="24" height="24" data-path="icons/xds/icon-people.svg">
    グループ会話に送信
  </Card>
</CardGroup>

***

## エンドポイント

| Method | Endpoint                                            | Description  |
| :----- | :-------------------------------------------------- | :----------- |
| POST   | `/2/dm_conversations`                               | 新しい会話を作成     |
| POST   | `/2/dm_conversations/with/:participant_id/messages` | 1 対 1 の会話に送信 |
| POST   | `/2/dm_conversations/:dm_conversation_id/messages`  | 既存の会話に送信     |
| DELETE | `/2/dm_events/:id`                                  | DM イベントを削除   |

***

## 例: メッセージを送信

```bash theme={null}
curl -X POST "https://api.x.com/2/dm_conversations/with/1234567890/messages" \
  -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"text": "Hello! How are you?"}'
```

## レスポンス例

```json theme={null}
{
  "data": {
    "dm_conversation_id": "1234567890-0987654321",
    "dm_event_id": "1122334455667788990"
  }
}
```

***

## メッセージタイプ

テキストメッセージを送信したり、メディアを添付したりできます。

```json theme={null}
{
  "text": "Check out this photo!",
  "attachments": [{
    "media_id": "1234567890123456789"
  }]
}
```

***

## はじめに

<Note>
  **前提条件**

  * 承認済みの [developer account](https://developer.x.com/en/portal/petition/essential/basic-info)
  * Developer Console 内の [Project と App](/resources/fundamentals/developer-apps)
  * [OAuth 2.0 PKCE](/resources/fundamentals/authentication#oauth-2-0-authorization-code-flow-with-pkce-2) で取得した User Access Token
</Note>

<CardGroup cols={2}>
  <Card title="クイックスタート" icon="https://mintcdn.com/x-preview-mintlify-5e62557c/7ox7QZkMlDBhUtvj/icons/xds/icon-rocket.svg?fit=max&auto=format&n=7ox7QZkMlDBhUtvj&q=85&s=b6c3ee24b3b5aff4ba4a87805d56fdc9" href="/x-api/direct-messages/manage/quickstart" width="24" height="24" data-path="icons/xds/icon-rocket.svg">
    最初の DM を送信
  </Card>

  <Card title="統合ガイド" icon="https://mintcdn.com/x-preview-mintlify-5e62557c/QVCcrJRuVU5c6Fli/icons/xds/icon-book.svg?fit=max&auto=format&n=QVCcrJRuVU5c6Fli&q=85&s=730ef6392554051da0ff5f79a1698c62" href="/x-api/direct-messages/manage/integrate" width="24" height="24" data-path="icons/xds/icon-book.svg">
    主要な概念とベストプラクティス
  </Card>

  <Card title="DM lookup" icon="messages" href="/x-api/direct-messages/lookup/introduction">
    DM イベントを取得
  </Card>

  <Card title="API リファレンス" icon="https://mintcdn.com/x-preview-mintlify-5e62557c/NnGYBQFO1PDkJQK7/icons/xds/icon-code.svg?fit=max&auto=format&n=NnGYBQFO1PDkJQK7&q=85&s=e6a5208c5ad4cc59a4a97fed7db5ed00" href="/x-api/direct-messages/create-dm-message-by-conversation-id" width="24" height="24" data-path="icons/xds/icon-code.svg">
    エンドポイントの完全なドキュメント
  </Card>
</CardGroup>
