1
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?

Google Sheetsとkintoneを連携した。

Last updated at Posted at 2024-03-12

Google Apps Scriptを使用してGoogle Sheetsの「行」追加時に自動でkintoneにレコード追加できるようにしました。

function addRecordToKintone() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var lastRow = sheet.getLastRow();
  var data = sheet.getRange(lastRow, 1, 1, sheet.getLastColumn()).getValues();
  
  // Kintone の設定
  var appUrl = 'https://ドメイン.cybozu.com/k/v1/record.json'; // アプリのURL
  var apiToken = 'APIトークン'; // APIトークン
  var appId = 'アプリID'; // アプリID
  var record = {
    'app': appId,
    'record': {
      'name': {
        'value': data[0][0] // スプレッドシートのデータ
      }
      // 他のフィールドも同様に追加
    }
  };
  
  // API コール
  var options = {
    'method' : 'post',
    'contentType': 'application/json',
    'headers': {'X-Cybozu-API-Token': apiToken},
    'payload' : JSON.stringify(record)
  };
  
  UrlFetchApp.fetch(appUrl, options);
}

1
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
1
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?