![]() |
VOOZH | about |
Interact with PingOne data from Google Sheets through macros, custom functions, and add-ons. The CData API Server enables connectivity to PingOne data from cloud-based and mobile applications like Google Sheets. The API Server is a lightweight Web application that produces OData services for PingOne.
Google Apps Script can consume these OData services in the JSON format. This article shows how to create a simple add-on that populates a Google Spreadsheet with [CData].[Administrators].Users data.
If you have not already done so, download the CData API Server. Once you have installed the API Server, follow the steps below to begin producing secure PingOne OData services:
To work with PingOne data from Google Sheets, we start by creating and configuring a PingOne connection. Follow the steps below to configure the API Server to connect to PingOne data:
To connect to PingOne, configure these properties:
is the ID of the PingOne environment in which your Worker application resides. This parameter is used only when the environment is using the default PingOne domain (auth.pingone). It is configured after you have created the custom OAuth application you will use to authenticate to PingOne, as described in Creating a Custom OAuth Application in the Help documentation.
First, find the value for this property:
WorkerAppEnvironmentId='11e96fc7-aa4d-4a60-8196-9acf91424eca'
Now set to the value of the Environment ID field.
is the base URL of the PingOne authorization server for the environment where your application is located. This property is only used when you have set up a custom domain for the environment, as described in the PingOne platform API documentation. See Custom Domains.
PingOne supports both OAuth and OAuthClient authentication. In addition to performing the configuration steps described above, there are two more steps to complete to support OAuth or OAuthCliet authentication:
Set to OAuth.
Get and Refresh the OAuth Access Token
After setting the following, you are ready to connect:
When you connect, the driver opens PingOne's OAuth endpoint in your default browser. Log in and grant permissions to the application. The driver then completes the OAuth process:
The driver refreshes the access token automatically when it expires.
For other OAuth methods, including Web Applications, Headless Machines, or Client Credentials Grant, refer to the Help documentation.
π Connecting to a datasource (SQLite is shown)Next, create a user to access your PingOne data through the API Server. You can add and configure users on the Users page. Follow the steps below to configure and create a user:
Having created a user, you are ready to create API endpoints for the PingOne tables:
Having configured a connection to PingOne data, created a user, and added resources to the API Server, you now have an easily accessible REST API based on the OData protocol for those resources. From the API page in API Server, you can view and copy the API Endpoints for the API:
π API EndpointsOpen the Script Editor from your spreadsheet by clicking Tools -> Script Editor. In the Script Editor, add the following function to populate a spreadsheet with the results of an OData query:
function retrieve(){
var url = "https://MyUrl/api.rsc/[CData].[Administrators].Users?select=Id,Id,Username,EmployeeType";
var response = UrlFetchApp.fetch(url,{
headers: {"Authorization": "Basic " + Utilities.base64Encode("MyUser:MyAuthtoken")}
});
var json = response.getContentText();
var sheet = SpreadsheetApp.getActiveSheet();
var a1 = sheet.getRange('a1');
var index=1;
var [cdata].[administrators].users = JSON.parse(json).value;
var cols = [["Id","Id","Username","EmployeeType"]];
sheet.getRange(1,1,1,4).setValues(cols);
row=2;
for(var i in [cdata].[administrators].users){
for (var j in [cdata].[administrators].users[i]) {
switch (j) {
case "Id":
a1.offset(row,0).setValue(account[i][j]);
break;
case "Id":
a1.offset(row,1).setValue(account[i][j]);
break;
case "Username":
a1.offset(row,2).setValue(account[i][j]);
break;
case "EmployeeType":
a1.offset(row,3).setValue(account[i][j]);
break;
}
}
row++;
}
}
Follow the steps below to add an installable trigger to populate the spreadsheet when opened:
After closing the dialog, you are prompted to allow access to the application.
You can test the script by clicking Publish -> Test as Add-On. Select the version, installation type, and spreadsheet to create a test configuration. You can then select and run the test configuration.
Learn more or sign up for a free trial:
CData API Server