Hi Phillip,
I think you are close but it looks like you took the example code from this article very literally:
https://developer.genesys.cloud/authorization/platform-auth/use-authorization-codeYou seem to be wrapping the client id and redirect_uri query parameters with "<" and ">" characters, which I assume you got from this code example:
https://login.mypurecloud.com/oauth/authorize
?client_id=<my-client-id>
&response_type=code
&redirect_uri=<http://example.com/oauth/callback>
In our docs we meant for you to replace the entire <my-client-id> and <http://example.com/oauth/callback> with the actual value. For instance, the actual request you send should look something like this:
https://login.mypurecloud.com/oauth/authorize?client_id=
069daa92-a113-4fed-825d-ba354482a193&response_type=code
&redirect_uri=https://www.myserver.com/mycode/callback
Also, Genesys Cloud orgs are hosted regionally. If your org is in the AWS US East region then the login request should be sent per the example to login.mypurecloud.com. But if it in a different region then you'll need to use the login URL for that region documented here:
https://developer.genesys.cloud/platform/api/That should help. If not you can post back here or on our developer forums at
https://developer.genesys.cloud/forumCheers,
------------------------------
Jim Crespino
Senior Director, Developer Evangelism
Genesys
https://developer.genesys.com------------------------------
Original Message:
Sent: 04-20-2022 09:45
From: Phillip Wright
Subject: OAuth2.0 Authentication
Hi,
I'm new to all of this and I am currently working on my first Genesys Cloud integration. When trying to authorize my application via OAuth2, I keep getting this error screen:
/** * Authorizes and makes a request to the API. */function run() { var service = getService(); if (service.hasAccess()) { var url = 'https://apps.mypurecloud.com/api/v2/authorization/divisions'; var response = UrlFetchApp.fetch(url, { headers: { Authorization: 'Bearer ' + service.getAccessToken() } }); var result = JSON.parse(response.getContentText()); Logger.log(JSON.stringify(result, null, 2)); } else { var authorizationUrl = service.getAuthorizationUrl(); Logger.log('Open the following URL and re-run the script: %s', authorizationUrl); }}/** * Reset the authorization state, so that it can be re-tested. */function reset() { getService().reset();}/** * Configures the service. */function getService() { return OAuth2.createService('Genesys') // Set the endpoint URLs. .setAuthorizationBaseUrl( 'https://login.mypurecloud.com/oauth/authorize?client_id=<' + CLIENT_ID + '>&response_type=code&redirect_uri=<' + REDIRECT_URI + '>') .setTokenUrl( 'https://apps.mypurecloud.com/oauth/token') // Set the client ID and secret. .setClientId(CLIENT_ID) .setClientSecret(CLIENT_SECRET) // Set the name of the callback function that should be invoked to // complete the OAuth flow. .setCallbackFunction('authCallback') // Set the property store where authorized tokens should be persisted. .setPropertyStore(PropertiesService.getUserProperties());}/** * Handles the OAuth callback. */function authCallback(request) { var service = getService(); var authorized = service.handleCallback(request); if (authorized) { return HtmlService.createHtmlOutput('Success!'); } else { return HtmlService.createHtmlOutput('Denied.'); }}
#Integrations
#Omni-ChannelDesktop/UserInterface
#SystemAdministration
------------------------------
Phillip Wright
Shipt, Inc.
------------------------------