☁️
Calendly Salesforce SDK
  • Getting Started
  • Core Concepts
    • Pagination
    • Error Handling
  • Classes
    • CalendlyApi
      • Organization
        • OrganizationMembership
          • OrganizationMembershipCollection
          • OrganizationMembershipResource
          • OrganizationMembershipPagination
          • OrganizationMembershipQueryParams
        • OrganizationInvitation
          • OrganizationInvitationResource
          • OrganizationInvitationCollection
          • OrganizationInvitationPagination
          • OrganizationInvitationQueryParams
      • User
        • UserResource
      • Invitee
        • InviteeResource
        • InviteeCollection
        • InviteeQueryParams
        • InviteePagination
        • InviteeQuestionsAndAnswer
        • InviteeTracking
        • InviteeCancellation
        • InviteePayment
      • ScheduledEvent
        • ScheduledEventPagination
        • ScheduledEventQueryParams
        • ScheduledEventCollection
        • ScheduledEventResource
        • EventMembership
        • EventGuest
        • ScheduledEventLocation
        • InviteesCounter
      • EventType
        • EventTypePagination
        • EventTypeQueryParams
        • EventTypeCollection
        • EventTypeResource
        • EventTypeProfile
      • SchedulingLink
      • WebhookSubscription
        • WebhookSubscriptionQueryParams
        • WebhookSubscriptionResource
        • WebhookSubscriptionCollection
        • WebhookSubscriptionPagination
        • VerifyWebhookResult
        • WebhookPayload
        • CreateWebhookSubscriptionRequest
      • SortParam
  • Advanced Concepts
    • Create Apex controller to receive webhook payload
Powered by GitBook
On this page

Was this helpful?

  1. Advanced Concepts

Create Apex controller to receive webhook payload

PreviousSortParam

Last updated 4 years ago

Was this helpful?

To receive webhook events from Calendly you'll need to add the apex controller class and any relevant objects/fields to your Site’s Public Access Settings (see ).

CalendlyWebhookController.cls
@RestResource(urlMapping='/fe92da7d')
global class CalendlyWebhookController {
    @HttpPost
    global static void doPost() {
      String signingKey = 'YOUR_WEBHOOK_SIGNING_KEY';
    	String requestBody = RestContext.request.requestBody.toString();
	    String webhookSignature = RestContext.request.headers.get('Calendly-Webhook-Signature');

      CalendlyApi.VerifyWebhookResult result = CalendlyApi.verifyWebhookSignature(webhookSignature, signingKey, requestBody);
	
	    if (!result.isValid) {
	       RestContext.response.responseBody = Blob.valueOf(result.errorMessage);
         RestContext.response.statusCode = 403;
	    } else {
	       JSONParser parser = System.JSON.createParser(requestBody);
         CalendlyApi.WebhookPayload webhookPayload = (CalendlyApi.WebhookPayload) parser.readValueAs(CalendlyApi.WebhookPayload.class);
         System.debug(webhookPayload.event + ' event received!');
	    }
   }
}

here