Recipe - Salesforce/Clockify integration

Clockify is a popular time tracking solution.

This integration uses a webhook to capture Time Entry events from Clockify and create corresponding Events in Salesforce with start and end times.

This recipe covers the integration in three steps.

Recipe
Step 1 - In Salesforce Flow, create the inbound webhook handler
Step 2 - In Clockify, create the outbound Time Entry publisher
Step 3 - Test the integration by recording some time in Clockify

Step 1 - Create the inbound webhook in Salesforce Flow

To secure the webhook endpoint, first create a Custom Metadata Type using protected records. This is the recommended best practice for storing the Clockify secret.

Now prepare the Flow to handle the webhook:

# Streamscript
$secret = $Webhook.requestHeaders.Clockify-Signature
if ($secret != {!Clockify_mdt}.Secret__c) {throw 'Bad Signature'}

# Parse the Clockify payload
$request = Json-Decode $Webhook.request

# Convert the TimeEntry to an Event
$Event = New-Event
$Event.Subject = 'Clockify'
$Event.StartDateTime = $request.timeInterval.start 
$Event.EndDateTime = $request.timeInterval.end
return $Event

To ensure the request is genuine, first read the Clockify secret from the webhook header, then compare it with the secret in custom metadata.

The script returns an event containing time entry data. Add a step to save the data:

Here is how the flow looks. To make sure the Site Guest User can insert the event record, go to Flow Properties > Advanced > How to Run the Flow: choose System Context Without Sharing.

Save the flow with the API Name: Webhook_Streams_Clockify

Note that the Flow API Name follows this three-part naming convention: Webhook_SiteName_PathSuffix

Step 2 - Configure the outbound webhook in Clockify

Create a new webhook:

Finally click the 'eye' icon and Copy the secret to the clipboard.

Step 3 - Test the integration

Last thing - before testing, store the Clockify secret in Salesforce.

Log into Clockify and go to Time Tracker:

Log into Salesforce and go to the Calendar Events tab. Here's the time entry!

This integration captured Time Entries as Salesforce Events using Streamscript and Clockify webhooks. The same pattern works with other Clockify data including Projects, Invoices, and Tasks.