37
32

More than 3 years have passed since last update.

ZoomのAPIを使ってみた

Posted at

 はじめに

Zoomの会議を作成するAPIを使ってみたので、備忘として手順を残します。
時世的にZoomを利用している方多いと思うので、参考になれば幸いです。

[準備] アプリの登録

マーケットプレイスからBuild Appを選択し、アプリの登録を進めます。
01_developer_sitte.png

今回のサンプルではJWTでの認証を選択します。
Choose your app typeでJWTのcreateボタンを押し、アプリの名前を設定します。
02_choose_app_type.png

続いて項目を埋めて行きます。赤枠で囲まれた必須項目のみ埋めています。
入力できたら右下のContinueを押します。
03_information.png

App Credentialsの画面でAPI KeyとAPI Secretが得られます。
この画面下部の「View JWT Token」を押すと期限付きのトークンが表示されます。
アプリケーションからAPIを呼び出す準備としてはここまでで完了です。
04_credential.png

サンプルプログラム

公式のnodeサンプルを参考にZoomの会議作成APIを実行するサンプルを作ってみます。
[サンプル]
https://github.com/zoom/zoom-api-jwt

[会議作成API仕様]
https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meetingcreate

[index.js] ※会議作成APIを実行して、レスポンスをテキストに書き出すサンプル


// 依存ライブラリ
const jwt = require('jsonwebtoken');
const rp = require('request-promise');
// 定数
const userId = 'xxx@xxx.com'; // Zoomアカウント(メールアドレス)
const apiKey = 'xxxxxxxxxxx'; // api key
const apiSecret = 'xxxxxxxx'; // api secret

// payload
const payload = {
   iss: apiKey,                            // API Keyを指定
   exp: ((new Date()).getTime() + 3600000) // トークン有効期限 1時間
};

// token生成
const token = jwt.sign(payload, apiSecret);

// APIリクエストの設定
let options = {
   method: 'POST',
   url: 'https://api.zoom.us/v2/users/' + userId + '/meetings',
   auth: { 'bearer': token },
   headers: {
       'User-Agent': 'Zoom-api-Jwt-Request',
       'content-type': 'application/json'
   },
   json: {
       'topic': 'test meeting',
       'type': '2',
       'start_time': getMeetingDate(), // 現在日時の1日後
       'timezone': 'Asia/Tokyo',
       'settings': { 'use_pmi': 'false' }
   }
};

// リクエスト
rp(options)
   .then(function (resJson) {
       writeToFile(resJson); // レスポンスをファイルに書き出す
   })
   .catch(function (err) {
       console.log(err);
   })

// getMeetingDate, writeToFileは省略

トークン生成

index.jsの抜粋。API実行に必要なトークンを実行ごとに生成しています。


// payload
const payload = {
   iss: apiKey,                            // API Keyを指定
   exp: ((new Date()).getTime() + 3600000) // トークン有効期限 1時間
};

// token生成
const token = jwt.sign(payload, apiSecret);

APIのパラメータ

index.jsの抜粋。APIのパラメータを設定しています。


let options = {
   中略
   json: {
       'topic': 'test meeting',
       'type': '2',
       'start_time': getMeetingDate(), // 現在日時の1日後
       'timezone': 'Asia/Tokyo',
       'settings': { 'use_pmi': 'false' }
   }
};

設定しているパラメータの説明。

パラメータ 説明
topic 会議のタイトル
type 会議タイプ。2を指定で会議予約。1だと即時。
3, 8で定期会議も設定可能
start_time 会議の開始時間。yyyy-MM-dd T HH:mm:ss形式。
timezone タイムゾーン指定。サポートするタイムゾーンの一覧
settings 各種設定
settings > use_pmi PMI(Personal Meeting ID)を使うかどうか。

実行結果


{
 "id": 11111111111,
 "join_url": "https://xxxxx.zoom.us/j/xxxx?pwd=xxxxx",
 "password": "xxxxxx"
}

よく使いそうなものだけ抜粋しました。
※ 全文はAPI仕様のReferenceを参照

idとpasswordは、まんま会議のID/PWで、join_urlが会議のURLです。
会議作成APIをアプリに組み込んだ場合、これらの情報をメールやチャットで相手に送るような使い方が多いかと思います。

参考

開発者ドキュメント
https://marketplace.zoom.us/docs/guides

APIリファレンス
https://marketplace.zoom.us/docs/api-reference/introduction

37
32
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
37
32