Webex API From WxCC
Webex CC Integrations are great for handling OAuth token management to your external API services, however, the methods which are required by Webex API, are not supported by WxCC Integrations. That leads me to this article, where I am going to show an alternate method, completely contained within Webex, to access the Webex APIs from within WxCC Flow Designer, oh and as a bonus, from WxConnect Flows as Custom Nodes as well!
Setup a Webex Service App
Create the Service App
- Go to http://developer.webex.com/ and sign in with your Webex account
- Click on your Avatar and then select My Webex Apps
- Create a new Service App
- Name it something cool like “Taserface”, or something more tame like “WxCC Flow Access.” It’s up to you!
- Select or upload your preferred icon
- Description is…stay with me here…where you describe what this integration does
- Contact email is whatever email you want to use
- The scopes are important and I cannot tell you what to check, but basically you need to know a few things:
- You cannot select all of them, there’s a limit to it
- Each API endpoint doc page lists which scopes are required, so use that as your guide, to which and how many scopes to check off
- For me, I am going to only select
spark-admin:people_read, so that I can lookup users in the directory
- For me, I am going to only select
- Click to Add Service App
- Copy your Client ID and Secret to your notes
Authorize the Service App
- Go to Control Hub https://admin.webex.com/
- Select Apps > Service Apps > Scroll the list and find “Taser Face” or whatever you called yours
- TIP: The search is by ID and not name, so if you search for “Taser” and see nothing, that’s why
- After selecting the Service App, flip on the Authorize togggle
Grab an Access Token and Refresh Token
- At this point, you’ll need to either refresh the Service App page you were on in the previous section, or just click off of it, and then back on to it, to see the new section titled “Org Authorizations”
- If you don’t see “Org Authorizations”, click refresh again
- Select your Org Name from the drop down list
- Paste your Client Secret into the field below the org name, and generate tokens
- Copy your Refresh and Access tokens to your notes
Configure WxCC Flow Designer
Now let’s move to the WxCC specific configurations, where we’ll setup a Global Variable, Subflow, and Main flow.
Store Access Token in WxCC Global Variable
When it comes to dynamic storage areas within WxCC, we don’t have much, but we do have read/write capabilities with our Global Variables, so that’s what we’re going to use, to grab the current access token, and also update it when it expires.
- Control Hub > Contact Center > Flow > Global Variables > Create
- Name is something like “WEBEX_ACCESS_TOKEN”
- Variable type is String
- Default value is your copied Access Token
- Save
- Click back into your newly created Global Variable and copy its Name and ID from the top of the page and put it in your notes
Enable WxCC API Integration
Since we will be updating the Global Variable dynamically, it will require us to access the WxCC API from within a Flow, and this is not on by default. If you already have a read/write integration already created, you can ignore this step, and we’ll just re-use what you already have.
- Control Hub > Contact Center > Integrations > Webex Contact Center > Add Connector
- Name like “WxCC API Access”
- Read-Write is required for us
- I authorize
- Click Add
Create a Subflow to Refresh the Token
While you do have the valid access token now available to your flows via the Global Variable, it will eventually expire, and then your API calls will start to fail.
What we need is, a subflow, so it’s reusable by all Flows, that will refresh our access token for us, and then update the Global Variable dynamically. The subflow will update the Global Variable but it will also return the access token as an output variable, so the already executing flow can obtain the new value immediately.
I have already created this subflow for you, we just need to import it, and tweak it a little.
- Control Hub > Contact Center > Flows > Subflows > Manage > Create > Import
- Import the file from this folder
- Now with the Flow Designer open, perform the following:
- Edit Flow variable
paramswith the values from your notes - Update the HTTP Request activity with name
UpdateGlobalVariableto use your connector from the previous section - Save, Validate & Publish
- Edit Flow variable
Create a Main Flow
The main flow will use the Global Variable to gain access to the current access token, so that you can call Webex APIs, but the main flow will also trigger the sublow above, as needed, just in case we receive a 401 Unauthorized response from the API.
I have already created this main flow for you, we just need to import it, and tweak it a little.
- Control Hub > Contact Center > Flows > Manage > Create > Import
- Import the file from this folder
- Now with the Flow Designer open, perform the following:
- Update the flow variable
target_userwith an email address of a user in your Org - Double check your Global Variable to make sure your’s is in the flow, and not mine: the one that came along with the import.
- Most likely, you will need to swap out the Global Variable in the flow with your own, as the export/import of Global Variables is a bit weird, in that the system will let you import a flow which references a Global Variable which doesn’t exist.
- This means that you will need to double check three activities:
- Your HTTP Request activity named
GetPersonDetailsto use your Global Variable name as the Bearer token. - Your Subflow activity named
RefreshTheTokento map your Global Variable- There should be one single output mapping from
access_tokento your Global Variable holding your access token
- There should be one single output mapping from
- Your Condition activity named
HaveAccessTokento check your Global Variable - Then delete the Global Variable that came along with the import if you did all of that work to update it to your own
- Your HTTP Request activity named
- Save, Validate & Publish
- Update the flow variable
Test
You should now be ready to attach this main flow to an Entry Point and phone number and then test it.
Configure WxConnect Flow Custom Nodes
We are going to repeat the work we did in the section Setup a Webex Service App, but unfortunately, we cannot use a Service App, so we’ll need to create an Intergration instead.
Buckle up though, as this process is not easy your first time through. Though, once you do create this, and it works, you should be able to enahance it beyond the example I lead you through.
Setup a Webex Integration
Create the Integration
- Go to http://developer.webex.com/ and sign in with your Webex account
- Click on your Avatar and then select My Webex Apps
- Create a new Integration
- Mobile SDK Usage is “No”
- Name it something cool
- Select or upload your preferred icon
- Provide a description
- Redirect URI is “https://oauth.us.webexconnect.io/callback”
- The scopes are important and I cannot tell you what to check, but basically you need to know a few things:
- You cannot select all of them, there’s a limit to it
- Each API endpoint doc page lists which scopes are required, so use that as your guide, to which and how many scopes to check off
- For me, I am going to only select
spark-admin:people_read, so that I can lookup users in the directory
- For me, I am going to only select
- Click to Add Integration
- Copy your Client ID and Secret to your notes
Create a Custom Node
- Control Hub > Contact Center > Webex Connect > Assets > Integrations > Add Integration > Custom Node
- Name is something like “Webex API”
- Rest API
- Description as you see fit
- Node Category as you see fit
- Creation Type from blank
- SVG for Node icon (there’s one here you can use)
Now, this next page you see is both the integration details (e.g., client ID and secret), but also the API call too (aka Request Method). The way WxConenct works is, each API call you would like to make, needs it’s own integration detail added, and each API call will obtain its own token. You are allowed 25 API calls per custom node.
Add a Request Method
I will replicate the same person lookup as we did for WxCC flow.
- Request Name is “GetPersonByEmail” or similar
- Request and Conenction Timeout is 2000ms or thereabouts
- Type is GET
- Resource URL is
https://webexapis.com/v1/people - Authorization
- Type is OAuth 2.0
- Grant Type is Authorization Code
- Consumer ID is your Client ID
- Consumer Secret is your Client Secret
- Authorization URL is
https://webexapis.com/v1/authorize - Scope is
spark-admin:people_read spark:kms- You may notice the
spark:kmsis new, but that’s not specific to WxConnect, it’s actually a hidden scope, that was just hidden from us previously, but we need to know about now.
- You may notice the
- Access Token URL is
https://webexapis.com/v1/access_token - Refresh Token URL is
https://webexapis.com/v1/access_token - Click the Access Token button
- A window should pop-up for you to complete the auth
- Confirm you now have an access token, and refresh token
- Scroll down to URL Parameters and add two parameters:
- Parameter is
emailfor one andcallingDatafor the other - Parameter Type is “Dynamic” for
emailand “Static” forcallingData - Field Name is “email” for
email - Parameter Value is
trueforcallingData
- Parameter is
- Scroll down to Response section and add two Node Events (like node outcomes)
- Node Name is “Success” for one, and “Error” for the other
- Switch Body to HTTP Status for both
- Condition is “equals” for Success and “not equals” for Error
- Value is
200for both - Node Edge is “Success” and “Error” respectively
- Still in the Response section, let’s add one response object
- Parameter name is “Person” is similar
- Body is Body
- Response Path is
$.items[0]- This means that if there is a returned person from the API call, the customer node will have an output variable called
personthat you can work with in the flow.
- This means that if there is a returned person from the API call, the customer node will have an output variable called
- Click Save
- [Optional] Click Test to perform a quick test
- Select Method Name from Drop Down
- Enter the email of one of your users
- Click Test and observe the output
- Click to go back by “Manage Custom Node” header at the top of the page
- Looking at the list of integrations, notice that your new integration is not toggled on right now, so you need to toggle it on, so that it’s visible in your WxConnect Flows.
Note: If you need to make more than just this one People lookup API call, you will need to repeat these steps again for each API call you configure.
Build a WxConnect Flow
We’ll build a simple Webhook based flow for testing the integration.
- WxConnect > Services > [choose any service or create a new one] > Flows > Create Flow
- Flow Name is “Testing Webex API” or similar
- Method is New Flow
- Select “Start from Scratch”
- Click Create
- Select Webhook as the Trigger
- Choose “Crete new event” radio button to create a new webhook URL
- Copy this URL for your notes, we’ll need it in a minute
- Name is “Testing Webex API” or similar
- Click Save
- Drag in your custom node (mine is called Webex API and has the Webex icon)
- Connect the Configure Webhook start node to it
- Double-click the Webex API node to open its properties
- Select the Method Name
- Enter the email address of one of your users
- Click Save to close the properties
- Drag in an Evaluate node
- Connect the custom node to it
- Double-click the Evaluate node to open its properties
- Use the following code in the node:
const person_json = JSON.parse("$(n3.person)"); const person_name = person_json.displayName; const person_status = person_json.status; const debug_data = JSON.stringify({ "person_name": person_name, "person_status": person_status, "person_json": person_json }); 0;- Script Output is
0 - Branch Name is “Success”
- Click Save to close the properties
- Click Make Live and wait until its Live
- Open Postman, or a similar app, and issue a POST request to your Webhook URL, with an empty JSON body of
{} - Go back to your Flow and click on the debugger, then click decrypt logs
- Find your transaction (there will likely only be one) and select it
- Look at your Evalute node’s outcome and you should see the
debug_datavariable populated with data from the API call (you’ll see some other variables there too)