Global

Methods

batch(rateLimitopt, lastExecutionDateopt) → {Batch}

Returns object on which you can use build batch request. The method Batch#add can be used to add requests to the queue. The method Batch#fetchAll is available which returns array of responses. Iteration over the instance is also possible. Rate limitation are either avoided, or handled.

Parameters:
Name Type Attributes Default Description
rateLimit Number <optional>
50
lastExecutionDate Date <optional>
null
Source:

createGoogEndpoint(name, version, resource, method) → {Endpoint}

Uses the Discovery API to create an endpoint with oauth already handled

Parameters:
Name Type Description
name String

Name of the service, i.e. "sheets"

version String

Version of the service, i.e. "v1"

resource String

the namespace i.e. "spreadsheets.values"

method String

the action at that namespace i.e. "get"

Source:
Example
const endpoint = Endpoints.createEndpointWithDiscoveryAPI('sheets', 'v4', 'spreadsheets', 'get');
endpoint.createRequest(...);

createGoogEndpointWithOauth(name, version, resource, method, oauth) → {Endpoint}

This creates an endpoint in which has custom oauth information, such as that needed for interacting with service that operates on a service account. The first four parameters need to be available in discovery

Parameters:
Name Type Description
name String
version String
resource String
method String
oauth Oauth
Source:
See:
  • Endpoint.discovery

createRequest(name, urlObj, options, mixinsopt) → {Request}

Create request objects

Parameters:
Name Type Attributes Description
name String

kind of http request: get, post, put, etc

urlObj Object

an object whose properties determine the target i.e. {url: 'https://example.com'} or {url: 'https://${domain}.com', domain: 'example'}

Properties
Name Type Attributes Description
url String

the url, with optional template

xyz String <optional>

when url is https://${xyz}.com and xyz is 'example.com' the url will be "https://example.com"

options Object

options containing query, payload, headers

Properties
Name Type Attributes Description
query Object <optional>

query parameters

payload Object <optional>

payload

headers Object <optional>

headers

mixins Object <optional>

Properties that will be available on the response

Source:
Throws:

Insufficient parameters if urlObj not built correctly

get(url, options) → {Object}

Simple interface for a get request, returns the response. If an error was found, it returns with error property. The parameters follow the same conventions as in UrlFetch.fetch(url, options).

Parameters:
Name Type Description
url String
options Object
Source:
Example
const result = Endpoints.get('https://example.com/s', {query: {s: 'searchstr'}});
Logger.log(result);  {error: {message:'404'}}

getOauthAsMe()

Returns a convenient class that has a token property which will authenticate requests with "you" via ScriptApp.getOauthToken

Source:

interpolate(baseUrlString, pathParameters) → {String}

Exposes the internal method used to substitute pathParameters objects to baseUrlString

Parameters:
Name Type Description
baseUrlString String
pathParameters Object
Source:
Example
const result = Endpoints.interpolate("https://example.com/${id}/something/${name}", {
    id: "12345",
    name: "ClassroomTechTools"
});
Logger.log(result);  // https://example.com/12345/something/ClassroomTechTools

iterator()

Respecting the rate limit (default value is low, pass higher value in constructor), fetch everything in chunks, returning each response one-by-one, making processing easier. Particularly useful if you know the rate limit (or just choose a sensible one)

Source:
Example
const batch = Endpoints.batch(200);  // 200 hits per second
for (let i=0; i<10000; i++) {
  const request = ...;
  batch.add(request);   // add 10,000 requests
}
for (const response of batch) {
  // you'll get each response one-by-one, but it'll chunk
  // by 200, and will wait for second to expire before the next chunk
  Logger.log(response.json);
}

makeGoogOauthService(service, email, privateKey, scopes) → {Oauth}

Returns service with oauth, for example for service accounts created on Google console

Parameters:
Name Type Description
service String

any name

email String

issuer email

privateKey String

from credentials json

scopes Array.<String>
Source:
See:
  • Endpoint.googOauthService

module()

Returns the class which can be used to build with UrlFetchApp. Not normally required.

Source:

post(url, options) → {Object}

Simple interface for a post request, returns the response. If an error was found, it returns with error property. The parameters follow the same conventions as in UrlFetch.fetch(url, options).

Parameters:
Name Type Description
url String
options Object
Source:
Example
const result = Endpoints.post('https://example.com/s', {payload: {password: 'password'}});
Logger.log(result);  {error: {message:'404'}}

resolveUrlInterpolation(str, pathParameters) → {String}

Exposes the internal method used to substitute raw url string returned by the discovery service to baseUrlString

Parameters:
Name Type Description
str String
pathParameters Object
Source:
Example
const result = Endpoints.resolveUrlInterpolation("https://example.com/{id}/something/{+name}", {
    id: "12345",
    name: "ClassroomTechTools"
});
Logger.log(result);  // https://example.com/12345/something/ClassroomTechTools

Type Definitions

urlParamsObj

Properties:
Name Type Description
url String

The url including query parameters

params Object

The parameters sent as second parameter to UrlFetchApp. Will optionally include a url property (when getParams is called with {embedUrl:true})

Source: