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?

Python+REST APIでkintoneのアプリからフィールドコードの一覧を取得する。

Posted at

kintoneのフィールドコードをPythonで読み込む

kintoneのアプリのフィールドコードの一覧を取得するコードです。
Copilotに出力させたコードだと動かなかったのは、get分の書き方が違っていたようです。

GetKintoneFieldCode.py
import requests

# kintoneの設定
subdomain = 'SUBDOMAIN'
app_id = 'APPID'
api_token = 'APITOKEN'

class KINTONE:
    def GetKintoneFields(self):
        # URL
        url = f'https://{subdomain}.cybozu.com/k/v1/app/form/fields.json'

        # ヘッダー
        headers = {
            'X-Cybozu-API-Token': api_token,
            'Content-Type': 'application/json'
        }

        # ボディ
        body = {
            'app' : app_id
        }

        # リクエストを送信
        # Copilotのコード
        # response = requests.get(url, headers=headers, params=body)
        response = requests.get(url, headers=headers, json=body)
        
        return response

if __name__ == '__main__':
    knt=KINTONE()
    resp=knt.GetKintoneFields()

    # レスポンスをJSON形式で取得
    fields = resp.json()

    # Field codeを表示
    if 'properties' in fields:
        for field_code, field_info in fields['properties'].items():
            print(f"Field Code: {field_code}, Field Name: {field_info['label']}")
    else:
        print(fields)
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?