2
3

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 1 year has passed since last update.

GASを使ってプリザンターにGoogleスプレッドシートの内容を登録する

Posted at

はじめに

GAS(Google Apps Script)を使って、Googleスプレッドシートの内容を プリザンター に登録することができます。

事前準備

  1. プリザンターの デモ環境 に登録します。
  2. テーブルを作成してURLに含まれるサイトIDを控えます。
  3. APIキーを作成 します。
  4. Googleスプレッドシートを作成します。
  5. A1セルにAPIキーを入力します。
  6. A2~A4セルにテストデータを入力します。

image.png

サンプルコード

プリザンターの デモ環境 で動作するGASのコードです。

function apiCreate(i) {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getActiveSheet();
  var apiKeyRange = sheet.getRange(1, 1);
  var titleRange =  sheet.getRange(i, 1);
  var data =
  {
    "ApiKey": apiKeyRange.getValue(),
    "Title": titleRange.getValue()
  };
  var options =
  {
    "method" : "post",
    "contentType": "application/json",
    "payload" : JSON.stringify(data)
  };
  var response = UrlFetchApp.fetch("https://demo.pleasanter.org/api/items/1234567/create", options);
}

function myFunction() {
  for (let i=2; i<5; i++) {
    apiCreate(i);
  }
}

補足情報

  • 事前準備で作成したテーブルのURLに含まれるサイトIDを指定しています。
  • テストレコード1~3をループして1件ずつレコードを作成しています。

動作結果

GASを動作させると、テストレコード1~3がプリザンターのテーブルに登録されます。
image.png

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?