0
1

kintone プラグイン一覧取得

Last updated at Posted at 2024-07-18

kintone REST API に、インストール済みプラグイン一覧取得が追加されたので、試してみました。

概要

既存のプラグインID を簡単に取得できます。

インストール済みのプラグインの一覧を取得する

開発は、kintone プラグインアップロード処理をもとにchatGPT で、API を変えてループ処理にしました。

プラグイン一覧表示

プラグインのインストール順に、表示されます。

実行ログ.log
> node .\scripts\listPlugin-api.js
*** Plugin List ***
# pluginId, name, version, pluginStore
1 gbjnadbngbniopdeibcjihdkhkcinljf : 項目絞り込み, 24, false
2 jaclnkdjcojbnailjnbfklhkcofaaeec : sample-test1, 1, false
3 bdikedheinambdonmgjghplaoakphdfd : 一括更新, 13, false
4 oliedeaopbljhpcolhigchoocbfjkcdj : 項目書式, 10, false
...
listPlugin-api.js
const axios = require('axios');
const yargs = require('yargs');

// 環境変数を取得します
const envDomain = process.env.KINTONE_DOMAIN;
const envUsername = process.env.KINTONE_USERNAME;
const envPassword = process.env.KINTONE_PASSWORD;

// 実行時パラメータを取得します
const argv = yargs
    .option('domain', {
        alias: 'd',
        description: 'Kintone domain',
        type: 'string',
        default: envDomain
    })
    .option('username', {
        alias: 'u',
        description: 'Kintone username',
        type: 'string',
        default: envUsername
    })
    .option('password', {
        alias: 'p',
        description: 'Kintone password',
        type: 'string',
        default: envPassword
    })
    .help()
    .alias('help', 'h')
    .argv;

// パラメータを変数に格納します
const subdomain = argv.domain;
const username = argv.username;
const password = argv.password;
const pluginFilePath = argv.file;

// 環境変数またはコマンドライン引数が不足している場合のチェック
if (!subdomain || !username || !password) {
    console.error('Domain, username and password must all be specified.');
    process.exit(1);
}

// プラグイン一覧を取得する非同期関数
async function getAllInstalledPlugins() {
    try {
        let allPlugins = [];
        let offset = 0;
        const limit = 100;
        let hasMore = true;

        // Kintoneのプラグイン一覧取得APIエンドポイント
        const pluginListUrl = `https://${subdomain}/k/v1/plugins.json`;

        // ヘッダーに基本認証を設定します
        const headers = {
            'X-Cybozu-Authorization': Buffer.from(`${username}:${password}`).toString('base64')
        };

        while (hasMore) {

            // プラグイン一覧取得リクエストを送信します
            const params = {
                offset: offset
            }
            const response = await axios.get(pluginListUrl, { headers: headers, params: { offset: offset } });

            // 取得したプラグインをリストに追加
            allPlugins = allPlugins.concat(response.data.plugins);
            offset += limit;

            // 取得したプラグインの数がlimit未満の場合、終了
            if (response.data.plugins.length < limit) {
                hasMore = false;
            }
        }

        return allPlugins;
    } catch (error) {
        console.error('エラーが発生しました。');
        console.error(error.response ? error.response.data : error.message);
    }
}

// plugin list
async function pluginList() {
    const resp = await getAllInstalledPlugins();
    const pInfo = resp.map((xx, idx) => {
        return (idx + 1) + ' ' + xx.id + ' : ' + xx.name + ', ' + xx.version + ', ' + xx.isMarketPlugin;
    }).join('\n');

    console.log('*** Plugin List ***\n# pluginId, name, version, pluginStore');
    console.log(pInfo);
}

pluginList();
0
1
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
0
1