LoginSignup
5
9

More than 5 years have passed since last update.

Python requestsモジュールを使用してKINTONEにデータを書き込む

Last updated at Posted at 2017-01-27

フロー

  1. KINTONEで入れ物を作る
  2. Pythonからデータ送る
  3. うれしい

KITONEの入れ物

今回は、"Text1"というフィールドコードを持つアプリを作りました。

Pythonからデータを送る

"abcde"というデータを書き込みます。

#!/usr/bin/python
# _*_ coding: utf-8 _*_

import requests


URL = "https://◯◯◯◯.cybozu.com:443" # URL
APP_ID = "APP ID" # kintoneのアプリID
API_TOKEN = "API TOKEN" # kintoneのAPIトークン


class KINTONE:
    def PostToKintone(self, url, appId, apiToken):
        #KINTONE field code: Text1
        record={'Text1':{'value' : 'abcde'}} #書き込むフィールドコードとデータ
        data = {'app':appId,'record':record}
        headers = {"X-Cybozu-API-Token": apiToken, "Content-Type" : "application/json"}
        resp=requests.post(url+'/k/v1/record.json',json=data,headers=headers)

        return resp


if __name__ == '__main__':
    knt=KINTONE()
    resp=knt.PostToKintone(URL, APP_ID, API_TOKEN)

    print resp.text

アウトプットは

{"id":"1","revision":"1"}

となり幸せな気分になりました。

5
9
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
5
9