Skip to content

@typedef doGet, doPost event parameter #31

Open
@oshliaer

Description

@oshliaer
/**
 * @typedef {Object} HTTPEvent
 * {@link https://developers.google.com/apps-script/guides/web Web Apps}
 * @property {string} queryString The value of the query string portion of
 *   the URL, or null if no query string is specified.
 * @property {object} parameter An object of key/value pairs that correspond to
 *   the request parameters.  Only the first value is returned for parameters
 *   that have multiple values.
 * @property {object} parameters An object similar to e.parameter, but with
 *   an array of values for each key.
 * @property {string} [contextPath=''] Not used, always the empty string.
 * @property {number} contentLength The length of the request body for
 *   POST requests, or -1 for GET requests.
 * @property {HTTPEventPostData} postData postData
 */

/**
 * @typedef {Object} HTTPEventPostData
 * @property {number} length The same as e.contentLength
 * @property {string} type The MIME type of the POST body
 * @property {string} contents The content text of the POST body
 * @property {string} postData Always the value "postData"
 */

/* exported doGet, doPost */
function doGet(e) {}

/**
 *
 * @param {HTTPEvent} e
 */
function doPost(e) {
  console.log(e.postData.contents);
  console.log(JSON.parse(e.postData.contents));
}

function example() {
  // Make a POST request with a JSON payload.
  var data = {
    name: 'Bob Smith',
    age: 35,
    pets: ['fido', 'fluffy']
  };
  var options = {
    method: 'post',
    contentType: 'application/json',
    // Convert the JavaScript object to a JSON string.
    payload: JSON.stringify(data)
  };
  UrlFetchApp.fetch('https://script.google.com/macros/s/xxx/exec', options);
}

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions