I am unable to validate my endpoint url

For example, when a Zoom meeting invite is sent via email, and the recipient opens the link and signs in, their information should be captured and stored in a custom Salesforce object.

I have created a public site in Salesforce, enabled my Apex class through public access settings, and set up a webhook app in the Zoom Marketplace.

However, when I enter my public site URL in the Event Notification Endpoint URL section in Zoom, I receive the error: “URL validation failed. Try again later.”

My apex class:
@RestResource(urlMapping=‘/zoomWebhook/*’)

global with sharing class ZoomWebhookHandler {

@HttpPost

global static void handleWebhook() {

    RestRequest req = RestContext.request;

    RestResponse res = RestContext.response;

    try {

        // Parse JSON request

        String requestBody = req.requestBody.toString();

        System.debug('Zoom Webhook Payload: ' + requestBody);

        Map<String, Object> jsonMap = (Map<String, Object>) JSON.deserializeUntyped(requestBody);

        Map<String, Object> payload = (Map<String, Object>) jsonMap.get('payload');

        if (payload != null) {

            String meetingId = (String) payload.get('id');

            List<Object> participants = (List<Object>) payload.get('participant');

            for (Object participantObj : participants) {

                Map<String, Object> participant = (Map<String, Object>) participantObj;

                String email = (String) participant.get('email');

                String userName = (String) participant.get('user_name');

                // Find the matching Contact

                List<Contact> contactList = [SELECT Id FROM Contact WHERE Email = :email LIMIT 1];

                if (!contactList.isEmpty()) {

                    // Create a new Zoom Meeting record

                    Zoom_Meeting__c zoomRecord = new Zoom_Meeting__c(

                        Contact__c = contactList[0].Id,

                        Meeting_ID__c = meetingId,

                        Participant_Email__c = email,

                        Participant_Name__c = userName

                    );

                    insert zoomRecord;

                }

            }

        }

        // Respond with HTTP 200 OK

        res.statusCode = 200;

        res.responseBody = Blob.valueOf('{"message": "Success"}');

    } catch (Exception e) {

        System.debug('Error processing webhook: ' + e.getMessage());

        // Respond with HTTP 400 Bad Request

        res.statusCode = 400;

        res.responseBody = Blob.valueOf('{"message": "Error: ' + e.getMessage() + '"}');

    }

}

Hi @Sridharan
Thanks for reaching out to us and welcome to the Zoom Developer Forum!
Have you been able to troubleshoot this on your end? are you able to validate your endpoint URL?

Hi @elisa.zoom,
I couldn’t troubleshoot my issue with my end. Thanks for replying for this.

Thanks for getting back to me @Sridharan
Looks like you are not validating your endpoint URL, here is a link to our Docs on how to do that:

Hi @elisa.zoom,
Thank you for getting back. apart from doc, can you figure out if there is any issue with my apex code?

Hey @Sridharan
Yes, you are not handling the endpoint URL validation. Make sure to include that in your code

This is a sample code snippet in node.js

const crypto = require('crypto')

// Webhook request event type is a challenge-response check
if(request.body.event === 'endpoint.url_validation') {
  const hashForValidate = crypto.createHmac('sha256', ZOOM_WEBHOOK_SECRET_TOKEN).update(request.body.payload.plainToken).digest('hex')

  response.status(200)
  response.json({
    "plainToken": request.body.payload.plainToken,
    "encryptedToken": hashForValidate
  })
}

Hi @elisa.zoom ,
Thank you for giving me this code. right now I’m working in apex code so do we need to include this node.js code with apex or convert this node.js into apex?

Hey there, you will need to convert the code into your apex