From 42f3a60e0d982f3242f6cfef3b4bcc2bdcfbdc2a Mon Sep 17 00:00:00 2001 From: "ry.yamafuji" Date: Sun, 7 Dec 2025 18:41:02 +0900 Subject: [PATCH] =?UTF-8?q?GAS=E3=81=AB=E3=81=A4=E3=81=84=E3=81=A6?= =?UTF-8?q?=E6=A7=8B=E7=AF=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/apiGet.js | 9 +++++++++ examples/apiPost.js | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 examples/apiGet.js create mode 100644 examples/apiPost.js diff --git a/examples/apiGet.js b/examples/apiGet.js new file mode 100644 index 0000000..5b7801d --- /dev/null +++ b/examples/apiGet.js @@ -0,0 +1,9 @@ +function callApiExample() { + const url = "https://jsonplaceholder.typicode.com/todos/1"; + + const response = UrlFetchApp.fetch(url); + const data = JSON.parse(response.getContentText()); + + const sheet = SpreadsheetApp.getActiveSheet(); + sheet.getRange(1, 1).setValue(data.title); // A1 に API のタイトルを書く +} \ No newline at end of file diff --git a/examples/apiPost.js b/examples/apiPost.js new file mode 100644 index 0000000..b522a71 --- /dev/null +++ b/examples/apiPost.js @@ -0,0 +1,17 @@ +function postApiExample() { + const url = "https://example.com/api"; + + const payload = { + name: "Yamada", + age: 30 + }; + + const options = { + method: "post", + contentType: "application/json", + payload: JSON.stringify(payload) + }; + + const response = UrlFetchApp.fetch(url, options); + Logger.log(response.getContentText()); +}