Skip to main content

$integration.customRequest

Advanced feature

This method executes a custom request to any method supported by the API of the integration connected to the project.

tip
In terms of basic functionality, this method is similar to $http.query. Use $integration.customRequest in its place for calling APIs which are only made available via an integration.

Syntax

$integration.customRequest(
integrationId,
url,
method,
headers,
body
);

Accepted arguments

The method accepts 5 required arguments.

ArgumentDescriptionType
integrationIdIntegration identifierString
urlMethod URLString
methodRequest methodString
headersRequest headersObject or null
bodyRequest bodyObject or null

Return value

The method returns an object with the following properties.

PropertyDescriptionType
statusCodeHTTP status codeNumber
responseHeadersResponse headersObject
responseBodyResponse bodyString

How to use

The following examples illustrate how to use $integration.customRequest to call the Google Sheets API methods.

The examples will assume that the integration and spreadsheet IDs are already defined as integrationId and spreadsheetId.

Read data from cells

Use the spreadsheets.values.get method to read spreadsheet data. The following method call retrieves data from the A1 cell on the first sheet:

$integration.customRequest(
integrationId,
"https://sheets.googleapis.com/v4/spreadsheets/" + spreadsheetId + "/values/A1",
"GET",
null,
null
);

If the sheet is called Sheet1 and the cell contains Hello, the return value will be the following object:

{
"statusCode": 200,
"responseHeaders": {
"Content-Type": "application/json; charset=UTF-8",
"Vary": "Origin",
// Other headers are omitted
},
"responseBody": "{\n \"range\": \"Sheet1!A1\",\n \"majorDimension\": \"ROWS\",\n \"values\": [\n [\n \"Hello\"\n ]\n ]\n}\n"
}
caution
Remember that responseBody is returned as a string. Use a deserialization method such as JSON.parse to transform it into an object and extract the necessary data.

Write data to cells

The spreadsheets.values.update method can update data already existing in the spreadsheet.

$integration.customRequest(
integrationId,
"https://sheets.googleapis.com/v4/spreadsheets/" + spreadsheetId + "/values/A1?valueInputOption=RAW",
"PUT",
null,
{values: [["Bye"]]}
);

If the method call is successful, the A1 value will be replaced with Bye. The response body will contain the updated cell range and the numeric values of updated cells, rows, and columns.

Copy sheets

Calling spreadsheets.sheets.copyTo copies sheets across spreadsheets. In this example, the first sheet (it has an ID of 0) is copied to the same spreadsheet. This is done by specifying the same spreadsheet ID as destinationSpreadsheetId.

$integration.customRequest(
integrationId,
"https://sheets.googleapis.com/v4/spreadsheets/" + spreadsheetId + "/sheets/0:copyTo",
"POST",
{"Content-Type": "application/json", "Connection": "Keep-Alive"},
{destinationSpreadsheetId: spreadsheetId}
);

A successful call will duplicate the sheet. The response body will contain the new sheet metadata, such as its ID and the number of rows and columns.