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()); +}