Posts

From Apeksh Dave: Create Zoom Meetings from Salesforce (with Scheduler)

Introduction

A customer of Salesforce is looking to integrate with Zoom and the Online Meeting capabilities from Salesforce using Portal / Internal screens. The use case is fairly straightforward, as a customer of a bank, I want to schedule an online meeting with my advisor and discuss my accounts. The technology the bank wants to use is Zoom.

The technology usage behind this particular demo is to simply create a meeting in Zoom via an API which returns a URL that parties can click on to launch Zoom( either browser or desktop ) and have a meeting. There is a lot more that can be done, but this integration is to show the possibilities with the connection

Technology Utilized

Listened below are the main technologies and configurations used in the demo preparation.

Main SaaS Tech Stacks

Demo Setup Technology

  • Zoom Development Account
  • Salesforce Org
  • Postman – To easily test the setup and API’s
  • <optional> Visual Code – Used to write and deploy code
  • Apex Classes
    • Invocable Methods setup to make available in Flows
    • Test Classes
  • Auth Provider Setup in Salesforce
  • Named Credentials
  • Salesforce Flows – To provide the screen navigation, call Zoom to get the meeting, and update the appropriate records.

Demo Flow High Level

This section describes the general flow of the demo from start to finish when showing to the customer. This is a specific flow for the customer this demo was prepared for. You can tailor or make your own flow(s) for your customer.

  • Customer goes to the portal to schedule a meeting, using the Salesforce Scheduler.
  • This demo has an authenticated flow, there is a person account associated with the demo.
  • Enter the required information from the screen
    • Click by previously scheduled service appointments or search for a banker.
    • Click Next
    • Click on a Work Type Group → Select the type => Click Next
    • Select Video Call
    • Enter a address → San Francisco → Select a branch
    • Choose a date in scheduler
    • The call to Zoom is done at this point and a URL is returned to the “Additional Information” Section. Note, this could be put anywhere but for the purpose of the meeting we chose here.
    • Click on next and a new Service Appointment is created with the Meeting URL in a custom field that can be accessed to launch a Zoom meeting.

The integration behind the scene created a Zoom meeting valid link that can be clicked on to start a Zoom meeting. This utilized the Zoom API, OAuth/Open ID authentication/authorization, and Apex Callout to create and return the meeting.

Demo Details

This section will describe the setup needed to execute the demo. What is described is the particular flow used to validate and test the integration. The entire section for Postman is completely optional, but it is suggested to do this to validate and debug. In our case, it was invaluable in determining the exact headers to place into the API. In the initial development, Postman was first used outside of Salesforce to ensure the API format was correct and the authentication/auth was setup correctly in Zoom.

Zoom Setup

The first piece that is needed is a Zoom Developer Account.  Please note you cannot use a Salesforce Zoom account as they have disabled permission to use the API.  Best bet create Personal Zoom account with personal ( no salesforce account) or working with your client account that allows to create meeting via API

image.png
  • Click on Create under OAuth.
image.png
  • Name it, choose an account level app and toggle off the publish button like this.
image.png
  • Next screen
    • Screen will show the client key, client secret. Copy & store in a secure place. You will need these in the Salesforce setup.
    • Populate the redirect url and add the allow list.
image.png
  • Enter developer name.
  • Scope is meeting:write:admin
  • Press install.

Setup Salesforce/Postman Application in Zoom

Salesforce Setup

This section describes the Salesforce Setup needed to access Zoom API meetings. It is strongly advised to setup Postman first to validate and test the API as well as get familiar with the API before jumping into Apex coding setup. This section will consist of Authentication setup, the Named Credential, and the Apex code needed to create a Zoom meeting and retrieve a URL. Additionally, this will provide the callback referenced in the Zoom section which will be needed to complete the Authentication section in Zoom.

Auth. Provider Setup

The first step is to create the Authorization Provider configuration to connect to Zoom. You will need the Secret Key(Value) from the Certificate setup in Zoom and the application id.

  1. Enter Salesforce Setup → Auth Providers → New.
  2. Choose Open ID Connect from the Provider Type drop-down.
  3. Name the Auth Provider.
  4. URL Suffix → Can make the same as the name.
  5. Consumer Key → This is the client key in Zoom.
  6. Consumer Secret → This is the client secret in Zoom.
image.png
  1. Authorization Endpoint URL – https://zoom.us/oauth/authorize see screen above.
  2. Token Endpoint URL – https://zoom.us/oauth/token see screen above.
  3. Default Scopes <optional> – meeting:write:admin
  4. Make sure this option is checked: Send client credentials in header.
  5. Use the defaults for the remainder.
  6. Save.
  7. Click on the newly defined Auth Provider to open it up.
  8. Copy the Callback URL that is shown in the Salesforce Configuration. If you have Experience Cloud setup and you are using those domains, then add those callback URLs as well to the Zoom Dev configuration.
  9. Take the callback URL you copied above and paste back in the Zoom redirect url & allow list. (Use the exact same word to word, no space.)
image.png

Named Credential

Creating a named credential will perform the authentication to Zoom and do the OAuth validation. Here is where the Zoom Authenticated App is used to validate the OAuth connection. (I set mine to auto approve.) It will prompt you to login to your instance of Zoom. The login will be the Zoom Developer login/id created during the setup of the developer instance.

  1. In Setup → Named Credentials, click New.
  2. Enter the label and the URL of the API Endpoint you wish to access. In this case, the full API is used for the onLineMeeting for Delegated access. The application access has a different signature
  3. Identify Type will be Named Principal.
  4. Auth Protocol will be OAuth 2.0.
  5. Select the Auth Provider created in the previous step.
  6. Scope: very important! The scope here will match the scope you created in Zoom for the application. It is space delimited.
    • meeting:write:admin
  7. Click on Generate Authorization Header.
  8. Check on Start Auth Flow on Save.
  9. Generate Auth Header is checked.
  10. Click Save. This will trigger the actual connection to Zoom and validate the Authentication.
  11. When you Save, the OAuth flow will initiate.
image.png
  • Zoom Login Screen will popup.
  • Login.
  1. If successful, you will see Authenticated in the Authentication Status in Salesforce. If it fails, you will get a failure screen from Zoom.  Common Issues:
  • Used the wrong secret key or id. Double check the values in the Auth. The Providers are correct.
  • URL Endpoint is invalid. Check your URL Endpoint. (Using Postman first helps avoid this issue.)

Salesforce Application Code

This section will review the Apex application code needed to make the Rest API call to setup a Zoom meeting and retrieve the meeting URL from the Zoom Server. The code is not production quality but instead is a sample to prove the concepts. The current iteration does not accommodate error handling in a meaningful way nor does it do much more than create a meeting. The goal of this good is to demonstrate the basic connection for the customer and proof of concept the meeting invites. The sample code will be in two parts, the first part is a test class that can be used to validate the connection and result. Once that is working, then the 2nd class uses @InvocableMethod so that it can be used in flows. Obviously this can be tailored however desired.

This section does not instruct how to setup command line tools, deploy the source, or other development tasks. It is assumed the reader understands how to deploy, run the developer tools/debugger in Salesforce.

Test Apex Class – Simple Class to Create the Meeting utilizing Named Credentials

public class TestZoomApi {

   /* Test Method for Unit Testing Connection */

   public static String getMeetingUrl()

   {

       HttpRequest req = new HttpRequest();

       Http http = new Http();

       //Setup the Endpoint and append the name of the file

       req.setEndpoint(‘callout:SalesforceZoomPOCNC’);

       req.setMethod(‘POST’);

       req.setHeader(‘Content-Type’,’application/json’);

       req.setHeader(‘Accept’,’*/*’);

       req.setHeader(‘Accept-Encoding’,’gzip, deflate, br’);

       //Setup the JSON Body – in the test just set a subject, can add more through Postman or other tests

       req.setBody(‘{“topic”: “test create meeting”,”type”: “1”}’);       

       //req.setBody(‘{}’);

       System.debug(‘Body: ‘ + req.getBody());

       System.debug(‘Endpoint Value: ‘+ req.getEndpoint());

       System.debug(‘Request: ‘ + req);

       HTTPResponse res = http.send(req);

       System.debug(‘Response Body: ‘+res.getBody());

       /* Parse Response */

       JSONParser parser = JSON.createParser(res.getBody());

       String webLink;

       webLink = ‘ZoomNotSetup’;

       while (parser.nextToken() != null) {

       if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&

       (parser.getText() == ‘join_url’)) {

           parser.nextToken();

           webLink = parser.getText();

           System.debug(‘join_url= ‘ + webLink);

           }

       }

   return webLink;

   }

}

Common Issues/Errors

  1. Zoom will return a 201 in the HTTP Response. This is a success. It is documented in the API.
  2. HTTP Error 500 – Internal Server Error
    1. Notice the headers that are set. The Zoom documentation does not state it explicitly, but in our testing we found that the 2 accept lines need to be in the header when sending the request. You need to add the gzip, etc and the “*/*” accept lines.
    2. 401 – The 401 unauthorized generally means the scope is incorrect in the Named Credential, or in the Named Credential and/or the Zoom setup. Make sure the permissions are correct and the scope is space delimited.
    3. 403 – Forbidden – This occurs when the secret keys are incorrect. You should have fixed this when you saved the name credential so it shouldn’t show up.
  3. Note: When using the Apex Debugger – Look for the debug line to joinWebURL populated with a long string for the meeting. It will start with something like this: 12:40:52:477 USER_DEBUG [37]|DEBUG|joinWebUrl= https://us04web.zoom.us/j/xxxxxxxxxx?pwd=xxxxxxxxxxxxxxxxx

Salesforce InvocableMethod Class Utilizing the Apex Code and Callout

This is the actual code used in the demonstration. This code is accessible in the Flow Builder inside of Salesforce as an Apex Action.

global class GetZoomMeetingURLwithInput {

   @InvocableMethod(label=’Get Zoom Meeting URL with Input’ description=’Returns a meeting URL For Zoom’)

   global static List<String> makeApiCalloutwithInput(List<List<String>> inputZoomsParms)

   {

       HttpRequest req = new HttpRequest();

       Http http = new Http();

       //Setup the Endpoint and append the name of the file

       req.setEndpoint(‘callout:SalesforceZoomPOCNC’);

       req.setMethod(‘POST’);

       req.setHeader(‘Content-Type’,’application/json’);

       req.setHeader(‘Accept’,’*/*’);

       req.setHeader(‘Accept-Encoding’,’gzip, deflate, br’);

        /* Setup the Parameters for Meetings, subject, etc. */

       // Note: The initial demo only utilized the title, further development can use other inputs.

       system.debug(‘Array size  =’ + inputZoomsParms.get(0).size()); 

       String inTitle = ‘”‘ + inputZoomsParms.get(0).get(0) + ‘”‘;

       system.debug(‘inTitle =’ + inTitle);   

       String inAgenda = ‘”‘ + inputZoomsParms.get(0).get(0) + ‘”‘;

       system.debug(‘inAgenda =’ + inAgenda);              

       String inPwd = ‘”‘ + inputZoomsParms.get(0).get(1) + ‘”‘;

       system.debug(‘inPwd =’ + inPwd);               

       String inStart = ‘”‘ + inputZoomsParms.get(0).get(2) + ‘”‘;

       system.debug(‘inStart =’ + inStart);               

       String inEnd = ‘”‘ + inputZoomsParms.get(0).get(3) + ‘”‘;

       system.debug(‘inEnd =’ + inEnd);

       //Setup the JSON Body – in the test just set a subject, can add more through Postman or other tests

       // req.setBody(‘{“topic”:’ + inTitle + ,”type”: “1”}’);       

       req.setBody(‘{“topic”: “test create meeting”,”type”: “1”}’);       

       //req.setBody(‘{}’);

       System.debug(‘Body: ‘ + req.getBody());

       System.debug(‘Endpoint Value: ‘+ req.getEndpoint());

       System.debug(‘Request: ‘ + req);

       HTTPResponse res = http.send(req);

       System.debug(‘Response Body: ‘+res.getBody());

       /* Parse Response */

       JSONParser parser = JSON.createParser(res.getBody());

       String webLink;

       webLink = ‘ZoomNotSetup’;

       while (parser.nextToken() != null) {

       if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&

       (parser.getText() == ‘join_url’)) {

           parser.nextToken();

           webLink = parser.getText();

           System.debug(‘join_url= ‘ + webLink);

           }

       }

   // Apex Actions Return. The method signature for an invocable method requires a List of Strings to be returned.

   return new List<String>{webLink};

   }

}

Salesforce User Experience Setup

This section is optional but describes how the above code can be accessed in the low-code building tools inside of Salesforce.

This section in a flow shows how this action is called to retrieve a URL for the Zoom Meeting and then assigns it to a Record (such as the Service Appointment, and/ or its associated Event) in Salesforce. A larger flow will then do further processing as part of a full scheduling flow. The takeaway is that the Apex Code above is an option to drag and drop into the low code builder and use it when running a flow. It could also be embedded within a Lightning Web Component(LWC) and used in other places. Alternatively, it can be accessed from another Apex Class to get the required information.

image.png

Postman Setup

This section describes how to setup Postman to access Zoom APIs and test the API integration outside of Salesforce in a developer-centric manner. This is completely optional, but oftentimes if it works in Postman and not in another application or Salesforce, you can see what is different in Postman versus the other applications. This tutorial assumes the reader is familiar with Postman and has downloaded the application or is using the web version. This document will use the desktop installation for reference. This section does not require knowledge of the Salesforce Setup. We recommend starting with Postman before the setup in Salesforce.

Postman Collection – use version 2 link below. (Do NOT use v1.)

Download the Zoom Postman Collection

To make life easier, download the Postman Collection already created for Zoom as plenty of examples. To do so:

Setup Postman Authentication

Setting up Authentication is straightforward and will require the client id and secret key from the Zoom setup done previously. Additionally, you will need to add the callback URL to the Authentication section in Zoom. You also need to setup Environment variables as part of this step.

Setup Zoom Dev account with Postman OAuth App

image.png
  • Click on Create under OAuth.
image.png
  • Name it, choose an account level app and toggle off the publish button like this.
image.png
  1. ClientID – will be the Application ID of the App you created in the Zoom dev account.
  2. Client Secret – will be the Client Secret in Zoom dev account.
  3. Make sure the Redirect url and Allow List are exactly this https://app.getpostman.com/oauth2/callback
image.png
  1. Enter developer name.
  2. Scope is
    • meeting:write:admin
  3. Press install.

Setup Postman authentication

  • Setup Zoom environment like this, and:
  • Edit api_key with Client ID from Zoom dev account.
  • Edit api_secret with client secret from Zoom dev account.
image.png
  • Go to Zoom Api. Right click. Edit, and:
    • Edit setup variable with baseurl.
image.png
  • Edit Authorization with appropriate info as shown below.
    • Make sure the callback url is exactly the same in the Zoom Dev account.
image.png
image.png
  • Get a new Access Token.
  • You will have to login in the Zoom account.

Get/Create and Run the Zoom Online Meeting API

image.png

{
“topic”: “test create5 meeting”,
“type”: “2”,
“start_time”: “2022-02-15T10:00:00”,
“duration”: “30”,
“registrants_email_notification”: “true”
}

  • Authentication – inherited from the parent.
  • Set this:
image.png