$integration.customRequest
Advanced feature
This method executes a custom request to any method supported by the API of the integration connected to the project.
$http.query
.
Use $integration.customRequest
in its place for calling APIs which are only made available via an integration.Syntax
Accepted arguments
The method accepts 5 required arguments.
Argument | Description | Type |
---|---|---|
integrationId | Integration identifier | String |
url | Method URL | String |
method | Request method | String |
headers | Request headers | Object or null |
body | Request body | Object or null |
Return value
The method returns an object with the following properties.
Property | Description | Type |
---|---|---|
statusCode | HTTP status code | Number |
responseHeaders | Response headers | Object |
responseBody | Response body | String |
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"
}
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.