Step 3: Create a Connection Object

The ADP Client Connection Library is intended to simplify and aid the process of authenticating, authorizing and connecting to the ADP API Gateway. The library supports OAuth2 Authorization Code and Client Credentials flows.

The library has been updated to add the ability to reconnect, and simplifies the configuration process for a connection by using JSON objects to configure the connection.

The code example below shows how to create a connection based on the updated Connection Library.

const adpConnection = require('adp-connection');

const init = {
     apiUrl: '',
     tokenUrl: '',
     authorizationUrl: '',
     sslCertPath: 'certs/apiclient_iat.pem',
     sslKeyPath: 'certs/apiclient_iat.key',
     granttype: 'client_credentials',
     clientId: ‘xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx’,
     clientSecret: ‘xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx’

const connection = adpConnection.createConnection(init);
connection.connect((err) => {
     console.log(‘Received: ', err, connection.accessToken);