Complete the steps described in the rest of this page, and in about five minutes you'll have a simple Google Apps Script that makes requests to the G Suite Reseller API.
Prerequisites
To run this quickstart, you'll need:
Step 1: Create the script
- Open Google Drive in your web browser.
- Click New > More > Google Apps Script.
If Google Apps Script isn't listed, you can install it by clicking the Connect more apps option instead. Search for "Google Apps Script" and click the +CONNECT button. Click the OK button in the popup, click the X icon to close the dialog, and repeat the step above.
- If you are presented with a welcome screen, click Blank Project.
-
Replace the contents of the script editor with the following code:
/** * Copyright Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function listSubscriptions() { var optionalArgs = { maxResults: 10 }; var response = AdminReseller.Subscriptions.list(optionalArgs); var subscriptions = response.subscriptions; if (subscriptions && subscriptions.length > 0) { Logger.log('Subscriptions:'); for (i = 0; i < subscriptions.length; i++) { var subscription = subscriptions[i]; Logger.log('%s (%s, %s)', subscription.customerId, subscription.skuId, subscription.plan.planName); } } else { Logger.log('No subscriptions found.'); } }
- Click File > Save, name your project “Quickstart”, and click OK.
Step 2: Turn on the G Suite Reseller API
- In the Apps Script editor, click Resources > Advanced Google Services.
- Locate Enterprise Apps Reseller API in the dialog and click the corresponding toggle, setting it to on.
- Click the Google API Console link.
- Enter "G Suite Reseller API" into the search box and click on the corresponding entry in the results.
- Click the Enable API button.
- Return to the Apps Script editor and click the OK button on the Advanced Google Services dialog.
Step 3: Run the sample
In the Apps Script editor, click Run > listSubscriptions.
The first time you run the sample, it will prompt you to authorize access:
- Click the Continue button.
- Click the Accept button.
To view the script's output, click View > Logs.
Further reading
- Google Apps Script Advanced Services documentation
- G Suite Reseller API codelab
- G Suite Reseller API reference documentation
Troubleshooting
ReferenceError: "[API NAME]" is not defined
This error occurs when the API hasn't been toggled on in the Apps Script code editor. Revisit Step 2.b and ensure the corresponding toggle is set to on.