2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【GAS】Chatworkの自分が参加しているグループチャット一覧を出力する

Last updated at Posted at 2021-03-31

※投稿内容は個人の学習目的の記事であり、所属組織とは一切関係ありません。
 Chatwork公式ドキュメントではございませんので、自己責任でご利用ください。

こんにちわ、さかぐち(@sakaguchi_mamii)です。

今回は、Chatworkの自分が参加しているグループチャットの一覧をスプレットシートに出力する方法をご紹介します。

APIトークンを取得する

右上のメニューから「API設定」を選択する。
API設定.png

パスワードを入力し、APIトークンを取得する。
スクリーンショット 2020-04-29 20.30.31.png

スプレットシートを作成し以下を設定する

シート名を「グループチャット一覧」に変更

グループチャット一覧.png

見出しをつける

スプレットシートに見出しをつける.png

1行目に以下の見出しを入力してください。

  • ルームID
  • チャット名
  • カテゴリー

「スクリプトエディタ」を開く

「スクリプトエディタ」を開く.png

スクリプト

const token = 'ここにAPIトークン';

function myFunction() {

  // スプレットシート読み込み
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet_rooms = ss.getSheetByName('グループチャット一覧');

  // グループチャット一覧取得
  var options = {
    headers : {'X-ChatWorkToken' : token},
    method : 'get',
  };
  var url = 'https://api.chatwork.com/v2/rooms';
  var respons = UrlFetchApp.fetch(url, options); 
  var json = JSON.parse(respons);

  // スプレットシート出力
  sheet_rooms.getRange(2,1,5000,3).clearContent(); // 既存データクリア
  var sheet_row = sheet_rooms.getLastRow()+1;
  for(var j=0; j<json.length; j++){
    sheet_rooms.getRange(sheet_row,1).setValue(json[j]['room_id']);
    sheet_rooms.getRange(sheet_row,2).setValue(json[j]['name']);
    sheet_rooms.getRange(sheet_row,3).setValue(json[j]['type']);
    sheet_row++;
  }
}

スクリプトを実行

スクリーンショット_2021-03-31_16_01_32.png

できた!

スクリーンショット_2021-03-31_13_56_10.png

最後に

今回はChatworkの自分のチャット一覧の取得APIを実行しました。
詳細は「Chatwork APIドキュメント」を参照ください。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?