I need to get a list of users and queues from Genesys and display them in a React/NodeJS app hosted on Amazon AWS. I want to use a Lambda function to get the lists and return them to the app.
The code here https://github.com/PrinceMerluza/prince-purecloud-aws-lambda-function/blob/master/main.py seems to be exactly what I need, once I translate from Python, but my attempt at authentication here returns an undefined access token:
const base64 = require('../../../../../node_modules/base-64');
//import { base64 } from 'js-base64';
const { resolve } = require('path');
const platformClient = require('purecloud-platform-client-v2/dist/node/purecloud-platform-client-v2.js');
const requests = require('../../../../../node_modules/request');
const usersApi = new platformClient.UsersApi();
const routingApi = new platformClient.RoutingApi();
const client = platformClient.ApiClient.instance;
const CLIENT_ID = '691982c9-ef27-4c8a-b41e-181db6aecc39';
const CLIENT_SECRET = 'U2gaFlTTkou46hEF-Rwi5pFho1nu0GCnh67nHdwX_3k';
//const authorization = base64.b64encode(`${CLIENT_ID}:${CLIENT_SECRET}`).decode('ascii');
const authorization = Buffer.from(`${CLIENT_ID}:${CLIENT_SECRET}`).toString('base64');
const aut2 = Buffer.from(authorization, 'base64').toString('ascii');
const requestHeaders = {
Authorization: `Basic ${aut2}`,
'Content-Type': 'application/x-www-form-urlencoded',
};
const requestBody = {
grant_type: 'client_credentials',
};
exports.handler = async (event) => {
const response = requests.post('https://login.mypurecloud.com/oauth/token', { data: requestBody, headers: requestHeaders });
const accessTokenInfo = response.json().access_token;
console.log("Access Token", accessTokenInfo);
return "success";
};
I think the issue is down to base64 encoding of the authorisation, but I've tried a few things and nothing works.
Is it even possible to call a Genesys API from a Lambda function? I've only found the one example and that isn't working.
So, this is how I would do it:
But if you want to do it with request (filename is
test.handler
):If you do want to use serverless to deploy this file (like I did), you will also need a
package.json
:And a
serverless.yml
:And the
env.dev
configuration properties file: