Salesforce/Clockify integration

Clockify tracks work hours on projects. The user starts and stops a timer to log time.

 

In this integration we will use a webhook to capture Time Entry messages sent from Clockify into Salesforce, so it creates Events showing the start and end times.

 

The recipe will build the integration in three steps:

 

Step 1 - Create the inbound webhook in Salesforce Flow

To secure any endpoint, we will first setup a Custom Metadata Type which supports protected records. This is a best practice and will be used to hold the Clockify webhook 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

The first line of the script references the Get Records step - to access the Clockify secret. It compares the stored secret to the incoming request header. Checking the secret ensures that only valid requests will be handled by the flow.

 

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

Here is how the flow looks. Just make sure the Site Guest User can insert the event record.
In Flow Properties > Advanced > How to Run the Flow: pick System Context With Sharing.

Save the flow with the API Name: Webhook_Streams_Clockify

 

Notice how the API Name of the Webhook Flow consists of three parts. This is a
convention and it always has the format: Webhook _ Site Name _ URL Suffix

 

Step 2 - Configure the outbound webhook in Clockify

 

Create a new webhook:

Finally click the 'eye' icon and Copy the Signing Secret to the clipboard.

 

Step 3 - Test the integration

Last thing - store your Clockify signing secrets into Salesforce before the test.

 

Log into Clockify and go to Time Tracker:

 

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

 

We hope you found this recipe useful. We captured Time Entries as Salesforce Events using Streamscript and Clockify webhooks. The same integration pattern works with other Clockify data including Projects, Invoices, or Tasks as your business requires.

 

 

Getting started with Streamscript
Install from the Salesforce AppExchange
Package install link: /packaging/installPackage.apexp?p0=04tGA000005R8Ny