Cannot read property 'proxy' of undefined

Hi,

I tried using the updated SDK (without any proxy) as follows (inside an async function):

const client = purecloudPlatform.ApiClient.instance;
client.setEnvironment('mypurecloud.ie');

await client.loginClientCredentialsGrant(oauth.clientId, oauth.clientSecret);

But I get the error message: TypeError: Cannot read property 'proxy' of undefined

Do I explicitly need to tell it to not use a proxy, or what am I missing?

I tried running the code with an earlier version of the SDK and it worked fine.

Thanks.

Can you provide more information about your environment and code? I just tested with this script using the node sdk v14.0.0 and am unable to reproduce this error. If you run the code below, do you still get the error?

const platformClient = require('purecloud-platform-client-v2');
const client = platformClient.ApiClient.instance;
client.setEnvironment('mypurecloud.com');

let usersApi = new platformClient.UsersApi();

client.loginClientCredentialsGrant(clientId, clientSecret)
	.then(() => usersApi.getUsers())
	.then((users) => {
		console.log(`User count: ${users.total}`);
	})
	.catch(function(response) {
		console.log(response);
	});

I'm wondering if whatever you've done with async functions is interfering with the context of this inside of ApiClient.js. Could you also provide the full stack trace for the error that shows exactly where it's coming from in the code?

I got the same error with the code you provided.

This is all the code excluding import and oauth:

const start = async () => {
  try {
    const client = purecloudPlatform.ApiClient.instance;
    client.setEnvironment('mypurecloud.ie');
    client.setDebugLog(console.log);

    await client.loginClientCredentialsGrant(
      oauth.clientId, oauth.clientSecret);
  } catch (e) {
    console.log(e);
  }
};

start();

Stack trace:

TypeError: Cannot read property 'proxy' of undefined
    at C:\Users\kripette\OneDrive - Atea\Utvikling\Github\purecloud-notifications-channel\node_modules\purecloud-platform-client-v2\src\purecloud-platform-client-v2\ApiClient.js:218:16
    at new Promise (<anonymous>)
    at exports.loginClientCredentialsGrant (C:\Users\kripette\OneDrive - Atea\Utvikling\Github\purecloud-notifications-channel\node_modules\purecloud-platform-client-v2\src\purecloud-platform-client-v2\ApiClient.js:209:12)
    at start (C:\Users\kripette\OneDrive - Atea\Utvikling\Github\purecloud-notifications-channel\example\app.js:14:18)
    at Object.<anonymous> (C:\Users\kripette\OneDrive - Atea\Utvikling\Github\purecloud-notifications-channel\example\app.js:30:1)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)

Sorry, I don't know what was wrong with my test yesterday. I've fixed this issue in 14.0.1. Thanks for your patience.

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.