Request

Request

Request instance. Instances of this class are created with createRequest. See below properties for properties and methods available

Constructor

new Request(main, url, oauth, method, headers, query, mixin)

Usually created on your behalf

Parameters:
Name Type Description
main Object

the first parameter

url String

the url (normally before query parameters)

oauth Any

oauth object, usually created via Oauth2 lib

method String

http method i.e. 'get' etc

headers Object

http headers

query Object

query parameters

mixin Any

adds properties in mixin object to the request obj via Object.assign

Properties:
Name Type Description
headers Object

The headers passed in

method String

"get" etc

query Object

what was passed to you

pathParams Object

an object that holds as keys/values what was passed in the second parameter, if any

Source:

Members

url

Calculates url, adding query parameters. In case key fields is non empty, converts with join(",") as needed by fields standard query param

Source:

Methods

addHeader(obj)

Adds header

Parameters:
Name Type Description
obj Object
Source:

addQuery(obj)

Copies key in obj to request object so that query parameters are passed on fetch

Parameters:
Name Type Description
obj Object

the object that is copied to queries object

Source:
Example
const request = Endpoints.createRequest('get', {
  url: 'https://example.com'
});
request.addQuery({p: 'str'});
request.url;  // https://exmaple.com?p=str

clearFields()

Sets _fields to empty array

Source:

clearQuery()

Sets this.query to empty object

Source:

fetch() → {Response}

Reach out to the internet with UrlFetchApp, returns Response object. Automatically detects rate limit, pauses, and tries again (just once)

Source:
Example
const request = Endpoints.createRequest('get', {
  url: 'https://example.com'
});
const response = request.fetch();
Logger.log(response.json);

getParams(embedUrl, muteExceptions) → {urlParamsObj}

Returns the param object required for UrlFetchApp.fetch or fetchAll

Parameters:
Name Type Description
embedUrl bool

if true add url property in object (needed for fetchAll)

muteExceptions bool

if true errors will be returned as jsons

Source:
Example
const req = Endpoints.createRequest('get', {
    url: 'http://example.com'
  }, {
    query: {p: 'str'}
  });
  const {url, params} = req.getParams();
  Logger.log(url);  // 'http://exmaple.com?p=str'
  Logger.log(params);  // {method: 'get', ...}

getUrl() → {String}

Alternative to this.url

Source:

setFields(value)

Pushes value to this.query.fields

Parameters:
Name Type Description
value String
Source: