google-apigoogle-admin-sdkgoogle-workspacegoogle-reseller-api

How to retrieve only the number of seats for all the subscriptions of my customers? (Google Workplace Reseller)


I am using the following JS code to retrieve seats details for all the subscriptions of my customers.

gapi.client.reseller.subscriptions.list()
  .then(function(response) {
    // Handle the results here (response.result has the parsed body).
    console.log("Response", response);
  },
  function(err) { console.error("Execute error", err); });

However, it's returning all of their other information as well. How can I customize it so that it only returns the number of seats?


Solution

  • Google APIs has a standard parameter called fields that allows you select which fields are included in the response (see documentation on Docs API).

    In Google API Client Library for JavaScript (aka gapi) you can simply add the parameters in an object when making a request. In your case this should work:

    gapi.client.reseller.subscriptions.list({
      fields: [
        'nextPageToken',
        'subscriptions/subscriptionId',
        'subscriptions/seats/numberOfSeats',
      ].join(',')
    })
    

    It's important to keep all fields that you need including control fields like nextPageToken. You can read more about the format used here.