0
0

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.

PerlAdvent Calendar 2019

Day 25

Perlでkintone REST API を利用する

Posted at

Perl Advent Calendar 2019 25日目の記事です。
kintoneとの連携しか思い浮かばなかったので、その記事です。

環境

  • Mac OS10.13.6
  • Homebrew
  • plenv
  • perl 5.30.1

フォームの設定の取得

kintoneのAPIを使って、フォームの設定情報を取得してみました。

コード

use strict;
use LWP::UserAgent;
use JSON;
use utf8;
use Encode;
use Data::Dumper; # debug
use Dotenv -load;
use MIME::Base64;
use base 'HTTP::Message';

my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 1 });
my $url = "https://${ENV{'SUBDOMAIN'}}.cybozu.com/k/v1/app/form/fields.json";
my $req = HTTP::Request->new(GET => $url);
$req->header("Host" => "${ENV{'SUBDOMAIN'}}.cybozu.com:443");
$req->header("X-Cybozu-Authorization" => encode_base64("${ENV{'UID'}}:${ENV{'PASS'}}", ''));
$req->header("Content-Type" => "application/json");
$req->content('{"app":1}');
my $res = $ua->request($req);
my $content = $res->content;
if ($res->is_success) {
    print $res->code, "\n";
    open(CMD, "| jq '.'");
    print CMD $content;
    close(CMD);
}else{
    print $res->status_line, "\n";
}

出力

jq を使って整形してみました。

200
{
  "revision": "20",
  "properties": {
    "レコード番号": {
      "type": "RECORD_NUMBER",
      "code": "レコード番号",
      "label": "レコード番号",
      "noLabel": false
    },
    "作業者": {
      "type": "STATUS_ASSIGNEE",
      "code": "作業者",
      "label": "作業者",
      "enabled": false
    },
    "Table": {
      "type": "SUBTABLE",
      "code": "Table",
      "fields": {
        "リンク_0": {
          "type": "LINK",
          "code": "リンク_0",
          "label": "E-mail",
          "noLabel": false,
          "required": false,
          "protocol": "MAIL",
          "minLength": "",
          "maxLength": "",
          "unique": false,
          "defaultValue": ""
        },
        "添付ファイル": {
          "type": "FILE",
          "code": "添付ファイル",
          "label": "写真",
          "noLabel": false,
          "required": false,
          "thumbnailSize": "50"
        },
        "ドロップダウン": {
          "type": "DROP_DOWN",
          "code": "ドロップダウン",
          "label": "担当者部門",
          "noLabel": false,
          "required": false,
          "options": {
            "製造部": {
              "label": "製造部",
              "index": "6"
            },
            "経営統括": {
              "label": "経営統括",
              "index": "0"
            },
            "経理": {
              "label": "経理",
              "index": "1"
            },
            "総務": {
              "label": "総務",
              "index": "2"
            },
            "情報システム": {
              "label": "情報システム",
              "index": "4"
            },
            "営業": {
              "label": "営業",
              "index": "3"
            },
            "生産管理": {
              "label": "生産管理",
              "index": "5"
            }
          },
          "defaultValue": ""
        },
        "文字列__1行__0": {
          "type": "SINGLE_LINE_TEXT",
          "code": "文字列__1行__0",
          "label": "担当者名",
          "noLabel": false,
          "required": false,
          "minLength": "",
          "maxLength": "",
          "expression": "",
          "hideExpression": false,
          "unique": false,
          "defaultValue": ""
        }
      }
    },
    "Address": {
      "type": "MULTI_LINE_TEXT",
      "code": "Address",
      "label": "住所",
      "noLabel": false,
      "required": false,
      "defaultValue": "〒"
    },
    "更新者": {
      "type": "MODIFIER",
      "code": "更新者",
      "label": "更新者",
      "noLabel": false
    },
    "作成者": {
      "type": "CREATOR",
      "code": "作成者",
      "label": "作成者",
      "noLabel": false
    },
    "文字列__1行_": {
      "type": "SINGLE_LINE_TEXT",
      "code": "文字列__1行_",
      "label": "顧客名",
      "noLabel": false,
      "required": true,
      "minLength": "",
      "maxLength": "",
      "expression": "",
      "hideExpression": false,
      "unique": false,
      "defaultValue": ""
    },
    "ステータス": {
      "type": "STATUS",
      "code": "ステータス",
      "label": "ステータス",
      "enabled": false
    },
    "ラジオボタン": {
      "type": "RADIO_BUTTON",
      "code": "ラジオボタン",
      "label": "顧客ランク",
      "noLabel": false,
      "required": true,
      "options": {
        "A": {
          "label": "A",
          "index": "1"
        },
        "B": {
          "label": "B",
          "index": "2"
        },
        "S": {
          "label": "S",
          "index": "0"
        },
        "C": {
          "label": "C",
          "index": "3"
        }
      },
      "defaultValue": "S",
      "align": "HORIZONTAL"
    },
    "更新日時": {
      "type": "UPDATED_TIME",
      "code": "更新日時",
      "label": "更新日時",
      "noLabel": false
    },
    "カテゴリー": {
      "type": "CATEGORY",
      "code": "カテゴリー",
      "label": "カテゴリー",
      "enabled": false
    },
    "リンク": {
      "type": "LINK",
      "code": "リンク",
      "label": "電話番号",
      "noLabel": false,
      "required": false,
      "protocol": "CALL",
      "minLength": "",
      "maxLength": "",
      "unique": false,
      "defaultValue": ""
    },
    "作成日時": {
      "type": "CREATED_TIME",
      "code": "作成日時",
      "label": "作成日時",
      "noLabel": false
    }
  }
}

次にやること

ExcelかCSVに出力して、設計情報を自動生成させたいです。

年末は他の方の記事を参考に、色々と試してみたいと思います。
それでは良いクリスマスを:santa:

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?