Ragini_Singh | 2022-04-20 05:37:40 UTC | #1
Hello,
We are facing an issue. When we are trying to get genesys cloud environment dynamically by using this code- var ClientApp = window.purecloud.apps.ClientApp; var myClientApp = new ClientApp({ pcEnvironmentQueryParam: 'pcEnvironment' });
it's giving me an error -Error: Invalid value for query param 'pcEnvironment' provided. Must be a non-null, non-empty string.
Thank You
Jerome.Saint-Marc | 2022-04-20 07:49:22 UTC | #2
Hello,
ClientApp SDK attempts to extract the environment value (region of the Genesys Cloud org) from the url query parameters. In your case (the code you have posted above), it means the ClientApp SDK expects a parameter named "pcEnvironment" to be present in the url (as query parameters). e.g. https://myapp.mydomain.com/mypage.html?pcEnvironment=mypurecloud.com
This is if you want to "dynamically" set the Genesys Cloud region - using a url parameter to pass the selected region. WebApps, embedded in Genesys Cloud, using a Client Application integration, can be declared leveraging URL interpolation, which will allow to dynamically pass some values. The following page describes its use with Client App SDK/
If you application is to work only in a single region, you can also set the region directly when calling the ClientApp constructor. e.g.
let clientApp = new ClientApp({ pcEnvironment: 'mypurecloud.com' });
As a last comment, note that ClientApp SDK only works if the web app/page is embedded inside Genesys Desktop, using a Client Application integration or an AppFoundry Premium app/widget.
Regards,
Ragini_Singh | 2022-04-22 06:40:14 UTC | #3
Hello Jerome,
Thank you for your suggestion. We have implemented your suggestion, we have passed query parameter in url https://myapp.mydomain.com/mypage.html?pcEnvironment={{pcEnvironment}} like this, It's giving pcEnvironment value on first load but on the 2nd load it's giving this error-
ERROR Error: Uncaught (in promise): Error: Invalid value for query param 'pcEnvironment' provided. Must be a non-null, non-empty string Error: Invalid value for query param 'pcEnvironment' provided. Must be a non-null, non-empty string at ClientApp.assertNonEmptyString
Could you please assist us on this.
Thank you
Jerome.Saint-Marc | 2022-04-22 15:54:11 UTC | #4
Hello,
There is not a lot of background information.... But I assume that what you are trying to do now is to get an access token from Genesys Cloud, to be able to leverage the Platform API endpoints, invoking the SDK loginImplicitGrant javascript method (OAuth Implicit Grant client).
In this process, the user (i.e. browser/web client) loads your application url. e.g. https://myserver.com/path/myapp.html?environment=mypurecloud.com Note that if your web app is exposed in Genesys Desktop as a custom client application integration, you can configure the url as: https://myserver.com/path/myapp.html?environment={{pcEnvironment}} (for Genesys Desktop URL interpolation)
In your app, you can retrieve the environment/region from the url query parameters (the first time the url is invoked/opened).
You can then set environment value for your Client App SDK and for the platfformClient (from the Platform API Javascript SDK).
Your app then triggers an OAuth Implicit Grant flow invoking the SDK loginImplicitGrant javascript method.
At the end of the OAuth Implicit Grant flow, the user (i.e. browser/web client) is redirected to the url you provided as redirectUri in loginImplicitGrant. As you have probably used the same url as redirect uri (i.e. https://myserver.com/path/myapp.html), the web client will load the application url again - but this time without the query parameters.
So you need to store or pass the original parameter (i.e. environment).
You can check this blog article which is explaining this.
There are several ways to manage this.
You can leverage javascript localStorage to store the environment parameter value (the first time the application url is invoked with the url query parameters), and to retrieve it from storage (the second time the application is invoked - on login redirect).
You can also leverage the oauth state parameter to pass the parameters value and retrieve them on redirect.
To give you an example of these.
For use of localStorage, you can have a look at this project/example - main.js file: https://github.com/MyPureCloud/purecloud-premium-app/blob/v1-legacy/docs/wizard/scripts/main.js The setup() function leverages the setDynamicParameters and authenticateGenesysCloud functions. setDynamicParameters extracts parameter values from url, if they are present, and store their values in localStorage; or read the values from localStorage if not present in url.
For use of oauth state parameter, you can have a look at this project/example - main.js file: https://github.com/MyPureCloud/purecloud-premium-app/blob/experimental/docs/wizard/scripts/main.js The setup() function leverages the getQueryParameters (from utils.js and authenticateGenesysCloud functions. getQueryParameters extracts query parameter values from url, if they are present, or checks if there is a hash parameter named state (and extract values from the state parameter) authenticateGenesysCloud will pass a set of values through the oauth state parameter in loginImplicitGrant.
You can use any of these 2 examples and modify the code to add the initialization of the ClientApp SDK with the value extracted from url
let clientApp = new ClientApp({ pcEnvironment: pcEnvironment });
Regards,
system | 2022-05-23 15:54:55 UTC | #5
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 14375