### Get My Status Endpoint Example Source: https://developer.chatwork.com/docs/endpoints This example shows the expected HTTP response headers and body for a successful GET /my/status request. Use this to retrieve your unread message counts. ```http HTTP/2 200 content-type: application/json ``` ```json { "unread_room_num": 2, "mention_room_num": 1, "mytask_room_num": 3, "unread_num": 12, "mention_num": 1, "mytask_num": 8 } ``` -------------------------------- ### cURL Example: Public Client Source: https://developer.chatwork.com/docs/oauth Example of how to issue a token using a `curl` command for a public client. ```APIDOC ```curl curl -v -X POST -d 'grant_type=authorization_code \ &client_id=Lvo0YN92ga5kP \ &code=26d13798facc9a0ca05a8cb7246020f15a311 \ &redirect_uri=https://127.0.0.1/callback &code_verifier=5b0029bd34e559e0abe7a37051aa411398913fc3579e27bd963a2b9a647f12f58a335beeb4d83a53a74ff1a6f99f6af385d2992c73beead39f57dcee95e0f954' \ https://oauth.chatwork.com/token ``` ``` -------------------------------- ### cURL Example: Confidential Client Source: https://developer.chatwork.com/docs/oauth Example of how to issue a token using a `curl` command for a confidential client. ```APIDOC ```curl curl -v --user 'Lvo0YN92ga5kP:secret' \ -X POST -d 'grant_type=authorization_code \ &code=26d13798facc9a0ca05a8cb7246020f15a311 \ &redirect_uri=https://127.0.0.1/callback \ &code_verifier=5b0029bd34e559e0abe7a37051aa411398913fc3579e27bd963a2b9a647f12f58a335beeb4d83a53a74ff1a6f99f6af385d2992c73beead39f57dcee95e0f954' \ https://oauth.chatwork.com/token ``` ``` -------------------------------- ### POST /token Request and Response Source: https://developer.chatwork.com/docs/oauth Example of a POST request to obtain an access token and the subsequent JSON response containing the token and other details. ```curl > POST /token HTTP/2 > Host: 127.0.0.1 > authorization: Basic THZvMFlOOTJnYTVrUDphYmNkZWZnaGlqa2xubW9wcXJzdHV2d3h5ejAxMjM0NTY3ODk= > accept: */* > content-length: 199 > content-type: application/x-www-form-urlencoded > < HTTP/2 200 < cache-control: no-store < pragma: no-cache < content-type: application/json < content-length: 989 { "access_token": "eyJjdHkiOiJKV1QiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImlOUVh0dFR2RHZhcDVkSWpGQzA5ZHZadHFXaGQ2WmFRb2pKenVuUS1vV28ifQ.eyJhdWQiOiJodHRwczovL2FwaS5jaGF0d29yay5jb20iLCJzdWIiOiIzIiwiYWNjb3VudF9pZCI6IjMiLCJzY29wZSI6WyJhbGwiXSwiaXNzIjoiaHR0cHM6Ly9vYXV0aC5jaGF0d29yay5jb20iLCJleHAiOjE1MDExMzgwNDEsImlhdCI6MTUwMTEzNzE0MSwianRpIjoiOTcwNDAwOWItNTdlNi00NDU5LTg5NzMtNjc3ZmM5YjA5MjgyIiwiY2xpZW50X2lkIjoiTHZvMFlOOTJnYTVrUCJ9.BIS8QvyTHz7KK_fnmvc0fa8NQDOWy7v8Ni0LvLyuROE5UEi7l_HxDT8tHLTQLELIm3jOw4SiW94KPYwduRL467vJ2j2eNT-zTkCXtEN8pxbA0HtnBrtCcp0dRJEMnfBegzkoAe8BTB6gee3rrXy6sQcLb19WBrrHNbjICFL0--SG3IvPanOzABqiNMqfScnasTtj7xtIaNpbxf8LDIH3EF150Iif4BqSczJr-XppBTBYuP32UlBnRlQOXvXqymGijQXgqDOo3LLFY_k62OoPYAQ3UXkaum86Al-DJM6iC-043kBINbYLLPo0uwwsolmjRDG5zBzPC0GtcjXiLy4Gqg", "token_type": "Bearer", "expires_in": 1800, "refresh_token": "86277ab4fd9d111bd3225215d96d622c9ae6810d82cd6d0e9530bf35adda67ab7d3c24e2a0052e9d3b442ce212ca17ecf07ddbd8c3477aa3abde15e4ebcf7b53", "scope": "rooms.all:read_write" } ``` -------------------------------- ### Obtain Access Token Source: https://developer.chatwork.com/docs/oauth This example shows how to request an access token using a POST request to the /token endpoint. The request includes basic authorization credentials and specifies the content type. ```APIDOC ## POST /token ### Description Requests an access token for authenticating with the Chatwork API. ### Method POST ### Endpoint /token ### Request Body - **grant_type** (string) - Required - Typically 'authorization_code' or 'refresh_token'. - **code** (string) - Required if grant_type is 'authorization_code' - The authorization code received from the user. - **refresh_token** (string) - Required if grant_type is 'refresh_token' - The refresh token to obtain a new access token. - **redirect_uri** (string) - Required if grant_type is 'authorization_code' - The redirect URI used during the authorization request. ### Request Example ```curl POST /token HTTP/2 Host: 127.0.0.1 authorization: Basic THZvMFlOOTJnYTVrUDphYmNkZWZnaGlqa2xubW9wcXJzdHV2d3h5ejAxMjM0NTY3ODk= accept: */* content-type: application/x-www-form-urlencoded grant_type=authorization_code&code=AUTHORIZATION_CODE&redirect_uri=REDIRECT_URI ``` ### Response #### Success Response (200) - **access_token** (string) - The obtained access token. - **token_type** (string) - The type of token, usually 'Bearer'. - **expires_in** (integer) - The token's validity period in seconds. - **refresh_token** (string) - The refresh token for obtaining new access tokens. - **scope** (string) - The granted scopes for the token. #### Response Example ```json { "access_token": "eyJjdHkiOiJKV1QiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImlOUVh0dFR2RHZhcDVkSWpGQzA5ZHZadHFXaGQ2WmFRb2pKenVuUS1vV28ifQ.eyJhdWQiOiJodHRwczovL2FwaS5jaGF0d29yay5jb20iLCJzdWIiOiIzIiwiYWNjb3VudF9pZCI6IjMiLCJzY29wZSI6WyJhbGwiXSwiaXNzIjoiaHR0cHM6Ly9vYXV0aC5jaGF0d29yay5jb20iLCJleHAiOjE1MDExMzgwNDEsImlhdCI6MTUwMTEzNzE0MSwianRpIjoiOTcwNDAwOWItNTdlNi00NDU5LTg5NzMtNjc3ZmM5YjA5MjgyIiwiY2xpZW50X2lkIjoiTHZvMFlOOTJnYTVrUCJ9.BIS8QvyTHz7KK_fnmvc0fa8NQDOWy7v8Ni0LvLyuROE5UEi7l_HxDT8tHLTQLELIm3jOw4SiW94KPYwduRL467vJ2j2eNT-zTkCXtEN8pxbA0HtnBrtCcp0dRJEMnfBegzkoAe8BTB6gee3rrXy6sQcLb19WBrrHNbjICFL0--SG3IvPanOzABqiNMqfScnasTtj7xtIaNpbxf8LDIH3EF150Iif4BqSczJr-XppBTBYuP32UlBnRlQOXvXqymGijQXgqDOo3LLFY_k62OoPYAQ3UXkaum86Al-DJM6iC-043kBINbYLLPo0uwwsolmjRDG5zBzPC0GtcjXiLy4Gqg", "token_type": "Bearer", "expires_in": 1800, "refresh_token": "86277ab4fd9d111bd3225215d96d622c9ae6810d82cd6d0e9530bf35adda67ab7d3c24e2a0052e9d3b442ce212ca17ecf07ddbd8c3477aa3abde15e4ebcf7b53", "scope": "rooms.all:read_write" } ``` #### Error Response - **www-authenticate** (string) - Contains error details if the token is invalid or expired. ``` -------------------------------- ### Authorization Header Example Source: https://developer.chatwork.com/docs/oauth Specifies the 'authorization' header format using the Bearer scheme with an access token for API requests. ```http authorization: Bearer eyJjdHkiOiJKV1QiLCJ0eXAiOiJKV1QiLCJhGciOiJSUzI1NiIsImtpZCI6ImlOUVh0dFR2RHZhcDVkSWpGQzA5Z HZadHFXaGQ2WmFRb2pKenVuUS1vV28ifQ.eyJhdWQiOiJodHRwcz ovL2FwaS5jaGF0d29yay5jb20iLCJzdWIiOiIzIiwiYWNjb3VudF9pZC I6IjMiLCJzY29wZSI6WyJhbGwiXSwiaXNzIjoiaHR0cHM6Ly9vYXV0a C5jaGF0d29yay5jb20iLCJleHAiOjE1MDExMzgwNDEsImlhdCI6MTU wMTEzNzE0MSwianRpIjoiOTcwNDAwOWItNTdlNi00NDU5LTg5NzMt Njc3ZmM5YjA5MjgyIiwiY2xpZW50X2lkIjoiTHZvMFlOOTJnYTVrUCJ9. BIS8QvyTHz7KK_fnmvc0fa8NQDOWy7v8Ni0LvLyuROE5UEi7l_Hx DT8tHLTQLELIm3jOw4SiW94KPYwduRL467vJ2j2eNT-zTkCXtEN 8pxbA0HtnBrtCcp0dRJEMnfBegzkoAe8BTB6gee3rrXy6sQcLb19 WBrrHNbjICFL0--SG3IvPanOzABqiNMqfScnasTtj7xtIaNpbxf8LDIH3E F150Iif4BqSczJr-XppBTBYuP32UlBnRlQOXvXqymGijQXgqDOo3LLFY _k62OoPYAQ3UXkaum86Al-DJM6iC-043kBINbYLLPo0uwwsolmjRD G5zBzPC0GtcjXiLy4Gqg ``` -------------------------------- ### Example Webhook Request Body Source: https://developer.chatwork.com/docs/webhook This is an example of the JSON payload received by your webhook URL when an event occurs. It includes event details and metadata. ```json { "webhook_setting_id": "12345", "webhook_event_type": "mention_to_me", "webhook_event_time": 1498028130, "webhook_event":{ "from_account_id": 123456, "to_account_id": 1484814, "room_id": 567890123, "message_id": "789012345", "body": "[To:1484814]おかずはなんですか?", "send_time": 1498028125, "update_time": 0 } } ``` -------------------------------- ### Redirect URL after Authorization Denial Source: https://developer.chatwork.com/docs/oauth Example of the redirect URI when a user denies authorization. The redirect includes an 'error' parameter set to 'access_denied' and the 'state' parameter. ```plaintext https://example.com/callback.php?error=access_denied ``` -------------------------------- ### API Rate Limit Information Source: https://developer.chatwork.com/docs/endpoints This example shows HTTP response headers indicating the API rate limit status. It includes the maximum calls allowed, remaining calls, and the time until the limit resets. ```http HTTP/2 200 content-type: application/json x-ratelimit-limit: 300 x-ratelimit-remaining: 244 x-ratelimit-reset: 1390941626 ``` -------------------------------- ### Curl Command to Access Chatwork API Source: https://developer.chatwork.com/docs/oauth Demonstrates how to use the `curl` command to make a GET request to the /me endpoint, including the authorization header. ```curl curl -v -H 'authorization: Bearer eyJjdHkiOiJKV1QiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImlOUVh0dFR2RHZhcDVkSWpGQzA5ZHZadHFXaGQ2WmFRb2pKenVuUS1vV28ifQ.eyJhdWQiOiJodHRwczovL2FwaS5jaGF0d29yay5jb20iLCJzdWIiOiIxNzMiLCJhY2NvdW50X2lkIjoiMTczIiwic2NvcGUiOlsiYWxsIl0sImlzcyI6Imh0dHBzOi8vb2F1dGguY2hhdHdvcmsuY29tIiwiZXhwIjoxNTAyMjUxNDU4LCJpYXQiOjE1MDIyNDk2NTgsImp0aSI6IjRlNzg5ZTAzLTk2NjAtNDc4MC1hYThkLTVmZjk2YmU0MzMyNSIsImNsaWVudF9pZCI6Ikx2bzBZTjkyZ2E1a1AifQ.Y14Sr0SmtgwLegwWPMeQlPut2XmP74y3QdupCAN7Hc5Id10Qvgq-csuYVxxAYStqZUO4sZ_j9SeE7-rqhuNowDMwqVaTGfDvAvtQLitPKDUb2g6x87c-lfffkJkIiL1xcH3lHrmQkBa_H81-_a3VFJila8hFptvygOp19OSDSrUIlcq6PeHlfNQtXjs2VFREQydQNE2cdLe68Nh5F5V4HX20C449MKNWK4ybwmFrnX-o9KgERaP1rjrCcWYrZ-lK8TquHti9XMfSaj71eDkfPVOLyCOe1_zBEEH8NRFtN2OcVQWJFPy09rz1yw7a1YARdsU4DukrhWvWcVxIad8ygA' \ 'https://api.chatwork.com/v2/me' ``` ```curl > GET /v2/me HTTP/2 > Host: api.chatwork.com > accept: */* > authorization: Bearer eyJjdHkiOiJKV1QiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImlOUVh0dFR2RHZhcDVkSWpGQzA5ZHZadHFXaGQ2WmFRb2pKenVuUS1vV28ifQ.eyJhdWQiOiJodHRwczovL2FwaS5jaGF0d29yay5jb20iLCJzdWIiOiIxNzMiLCJhY2NvdW50X2lkIjoiMTczIiwic2NvcGUiOlsiYWxsIl0sImlzcyI6Imh0dHBzOi8vb2F1dGguY2hhdHdvcmsuY29tIiwiZXhwIjoxNTAyMjUxNDU4LCJpYXQiOjE1MDIyNDk2NTgsImp0aSI6IjRlNzg5ZTAzLTk2NjAtNDc4MC1hYThkLTVmZjk2YmU0MzMyNSIsImNsaWVudF9pZCI6Ikx2bzBZTjkyZ2E1a1AifQ.Y14Sr0SmtgwLegwWPMeQlPut2XmP74y3QdupCAN7Hc5Id10Qvgq-csuYVxxAYStqZUO4sZ_j9SeE7-rqhuNowDMwqVaTGfDvAvtQLitPKDUb2g6x87c-lfffkJkIiL1xcH3lHrmQkBa_H81-_a3VFJila8hFptvygOp19OSDSrUIlcq6PeHlfNQtXjs2VFREQydQNE2cdLe68Nh5F5V4HX20C449MKNWK4ybwmFrnX-o9KgERaP1rjrCcWYrZ-lK8TquHti9XMfSaj71eDkfPVOLyCOe1_zBEEH8NRFtN2OcVQWJFPy09rz1yw7a1YARdsU4DukrhWvWcVxIad8ygA > < HTTP/2 200 < content-type: application/json; charset=utf-8 < content-length: 412 < connection: keep-alive < x-ratelimit-limit: 300 < x-ratelimit-remaining: 299 < x-ratelimit-reset: 1502250163 < vary: Accept-Encoding,User-Agent < {"account_id":1, ...(略) } ``` -------------------------------- ### Authorization Header for Confidential Clients Source: https://developer.chatwork.com/docs/oauth Example of the 'Authorization' header for confidential clients using Basic Authentication. The username is the client ID and the password is the client secret, combined and Base64 encoded. ```http authorization: Basic THZvMFl1OO== ``` -------------------------------- ### API Token Error Example Source: https://developer.chatwork.com/docs/endpoints This example illustrates the HTTP response for an authentication error (invalid API token). The response includes a 401 status code and an error message in the JSON body. ```http HTTP/2 401 content-type: application/json ``` ```json { "errors": ["Invalid API token"] } ``` -------------------------------- ### Example Authorization URL for Consent Screen Source: https://developer.chatwork.com/docs/oauth Constructs the URL to display the consent screen for OAuth 2.0 authorization. Includes parameters like response_type, redirect_uri, client_id, state, scope, code_challenge, and code_challenge_method. ```text https://www.chatwork.com/packages/oauth2/login.php? response_type=code &redirect_uri=https://example.com/callback.php &client_id=Lvo0YN92ga5kP &state=811435b3683ae95c1cf3197deaf1bfe4b411f587 &scope=rooms.all:read_write%20users.profile.me:read &code_challenge=jlkGAsNvHshJNC7uXSSmC2tALONajPdupVf3TScb7zk &code_challenge_method=S256 ``` -------------------------------- ### cURL Command for Token Issuance (Public Client) Source: https://developer.chatwork.com/docs/oauth Example cURL command to issue an access token for a public client using the authorization code grant type. Requires client ID and specific parameters, but not a secret. ```curl curl -v -X POST -d 'grant_type=authorization_code \ &client_id=Lvo0YN92ga5kP \ &code=26d13798facc9a0ca05a8cb7246020f15a311 \ &redirect_uri=https://127.0.0.1/callback &code_verifier=5b0029bd34e559e0abe7a37051aa411398913fc3579e27bd963a2b9a647f12f58a335beeb4d83a53a74ff1a6f99f6af385d2992c73beead39f57dcee95e0f954' \ https://oauth.chatwork.com/token ``` -------------------------------- ### cURL Command for Token Issuance (Confidential Client) Source: https://developer.chatwork.com/docs/oauth Example cURL command to issue an access token for a confidential client using the authorization code grant type. Requires client credentials and specific parameters. ```curl curl -v --user 'Lvo0YN92ga5kP:secret' \ -X POST -d 'grant_type=authorization_code \ &code=26d13798facc9a0ca05a8cb7246020f15a311 \ &redirect_uri=https://127.0.0.1/callback \ &code_verifier=5b0029bd34e559e0abe7a37051aa411398913fc3579e27bd963a2b9a647f12f58a335beeb4d83a53a74ff1a6f99f6af385d2992c73beead39f57dcee95e0f954' \ https://oauth.chatwork.com/token ``` -------------------------------- ### Mention to Me Event Object Example Source: https://developer.chatwork.com/docs/webhook This JSON object represents a webhook event when a user is mentioned in a message. It contains sender and receiver account IDs, room ID, message details, and timestamps. ```json { "from_account_id": 1234567890, "to_account_id": 1484814, "room_id": 567890123, "message_id": "789012345", "body": "[To:1484814]おかずはなんですか?", "send_time": 1498028125, "update_time": 0 } ``` -------------------------------- ### Redirect URL after Authorization Code Issuance Source: https://developer.chatwork.com/docs/oauth Example of the redirect URI after a user grants authorization. The redirect includes the authorization 'code' and the 'state' parameter previously provided. ```plaintext https://example.com/callback.php? code=a2f0c1fe96af8c3a46fa0 &state=811435b3683ae95c1cf3197deaf1bfe4b411f587 ``` -------------------------------- ### API Rate Limit Exceeded Error Source: https://developer.chatwork.com/docs/endpoints This example demonstrates the HTTP response when the API rate limit is exceeded. It returns a 429 status code and indicates that no more requests can be made until the reset time. ```http HTTP/2 429 content-type: application/json x-ratelimit-limit: 300 x-ratelimit-remaining: 0 x-ratelimit-reset: 1390941626 ``` -------------------------------- ### Message Creation Event Object Example Source: https://developer.chatwork.com/docs/webhook This JSON object represents a webhook event when a new message is created. It includes details such as message ID, room ID, sender information, message body, and timestamps. ```json { "message_id": "789012345", "room_id": 567890123, "account_id": 1484814, "body": "お客様とのランチミーティング用のお弁当、発注完了しました。", "send_time": 1498028120, "update_time": 0 } ``` -------------------------------- ### Parameters for Initial Token Issuance Source: https://developer.chatwork.com/docs/oauth Table detailing parameters for obtaining an access token using an authorization code. Ensure 'redirect_uri' matches the one used during authorization if specified. ```html
| パラメーター名 | 指定する値 | 必須 | 例 |
|---|---|---|---|
| grant_type | 文字列 | ◯ | authorization_codeを指定してください。 |
| code | 文字列 | ◯ | 認可許可ボタンを押して取得した認可コードを指定してください。 |
| redirect_uri | 文字列 |
コンセント画面を表示する際に 例: |
|
| code_verifier | 文字列 | ※ |
認可リクエストで 文字列長は43文字から128文字、文字種としては正規表現で |
| パラメーター名 | 指定する値 | 必須 | 説明 |
|---|---|---|---|
| response_type | 文字列 | ◯ | 現在はcodeにしか対応していません。 |
| client_id | 文字列 | ◯ | クライアントIDを指定してください。 |
| redirect_uri | 文字列 |
クライアント登録時に設定したURIの中から指定してください。 例: 複数の |
|
| scope | 文字列 | ◯ |
スコープをスペース区切りで指定してください。 例:
|
| state | 文字列 |
CSRF攻撃対策として使う文字列で、リソースオーナーのセッションに紐づけて管理します。リソースオーナーが認可許可または認可拒否を行ったとき、ここでセットした 例: The OAuth 2.0 Authorization Framework 10.12. Cross-Site Request Forgery |
|
| code_challenge | 文字列 | ※ |
コンフィデンシャルクライアントの場合は任意、 値は後にトークンエンドポイントで使用する
算出結果の文字列長は43文字から128文字、文字種としては正規表現で |
| code_challenge_method | 文字列 | ※ |
コンフィデンシャルクライアントの場合は任意、
|
| パラメーター名 | 指定する値 | 必須 | 例 |
|---|---|---|---|
| grant_type | 文字列 | ◯ | refresh_tokenを指定してください。 |
| refresh_token | 文字列 | ◯ | トークン発行時に生成されたrefresh_tokenの値を指定してください。 |
| scope | 文字列 |
スコープをスペース区切りで指定してください。 例: |