[Google Apps Script] Send a POST request with a JSON body

Created on November 30, 2026

You can use UrlFetchApp.fetch() to send an HTTP POST request. Pass the endpoint URL as the first argument and a request options object as the second.

function sendPostRequest() {
  const options = {
    method: "post",
    contentType: "application/json",
    payload: JSON.stringify({ text: "Hello" }),
  };

  const response = UrlFetchApp.fetch("https://example.com/messages", options);
  console.log(response.getResponseCode());
}

Replace the example URL with the endpoint that accepts the request. JSON.stringify() serializes the object as the JSON string sent in the request body. The example logs the server's status code on a successful request.

Reference

Google Apps Script