Client CraftClient Craft HubStart free

Receive and verify CRM webhook events

On this page
Updated 24 Nov 20264 min read

Handle Client Craft webhook deliveries: headers, payload, HMAC-SHA256 signature check, retries, duplicates and secret rotation, with a C# receiver.

Plan: All plans

Each webhook delivery is a signed POST. Your receiver checks the signature on the raw body, records the delivery id so retries aren't processed twice, answers 2xx quickly and does the real work in the background.

Before you start #

  • A webhook created in Settings › Integrations and its signing secret. See Create workspace API keys and webhooks.
  • A public https:// endpoint that accepts POST requests and can read the raw request body before any JSON parsing.

How it works #

  1. 1
    Know what each request containsEvery delivery is a POST with a JSON body (application/json) and these headers:
    HeaderMeaning
    X-uCRM-Event-DeliveryDelivery id; the same across retries. Test events send test
    X-uCRM-Event-TimestampUnix time in seconds when this attempt was signed
    X-uCRM-Signaturev1= followed by a lowercase hexadecimal HMAC-SHA256
    X-uCRM-Event-Testtrue on test events only
  2. 2
    Read the payloadThe body is the CRM event in camelCase JSON. The fields you will use most are id, tenantId, eventKey, category, source, entityType, entityId, leadId, contactId, accountId, dealId, invoiceId, actorType, actorLabel, correlationId, properties, changedFields, occurredAtUtc and createdAtUtc. changedFields is a list of objects with field, previousValue and newValue. Fields that don't apply are null. A test event is synthetic: eventKey is webhook.test, test is true and data holds a message.
  3. 3
    Pick the eventsA webhook with no events ticked receives every event. Examples from the catalogue:
    AreaEvent keys
    Leadscrm.lead_created, crm.lead_updated, crm.lead_status_changed, crm.lead_converted
    Contacts, companies, dealscrm.contact_created, crm.account_created, crm.deal_created, crm.deal_stage_changed
    Proposals, invoicescrm.proposal.viewed, crm.proposal.accepted, crm.invoice_created, crm.invoice_paid
    Bookings, tasks, projectscrm.booking_confirmed, crm.booking_cancelled, crm.task_completed, crm.project_created
    Formsmarketing.form_submitted, marketing.list_subscribed

    The Events list in the Add webhook dialog shows the full catalogue for your workspace.

  4. 4
    Verify the signatureBuild the string timestamp.body from the X-uCRM-Event-Timestamp value, a dot and the raw body. Compute HMAC-SHA256 over it with the whole signing secret (UTF-8, including ucrm_whsec_) as the key, encode it as lowercase hex and prefix v1=. Compare it with X-uCRM-Signature in constant time.

    A complete ASP.NET Core receiver (Program.cs of a Microsoft.NET.Sdk.Web project on .NET 10):

    csharp
    1using System.Security.Cryptography;
    2using System.Text;
    3
    4var builder = WebApplication.CreateBuilder(args);
    5var app = builder.Build();
    6
    7app.MapPost("/client-craft/webhooks", async (HttpRequest request, IConfiguration config) =>
    8{
    9 // Read the raw body exactly as sent; never re-serialize the JSON before checking it.
    10 using var reader = new StreamReader(request.Body, Encoding.UTF8);
    11 var body = await reader.ReadToEndAsync();
    12
    13 var timestamp = request.Headers["X-uCRM-Event-Timestamp"].ToString();
    14 var signature = request.Headers["X-uCRM-Signature"].ToString();
    15 var secret = config["ClientCraft:WebhookSecret"]; // ucrm_whsec_..., from your secret store
    16 if (string.IsNullOrEmpty(secret)) return Results.StatusCode(StatusCodes.Status500InternalServerError);
    17
    18 // Our recommendation: reject stale timestamps (here, older than five minutes).
    19 if (!long.TryParse(timestamp, out var seconds)
    20 || Math.Abs(DateTimeOffset.UtcNow.ToUnixTimeSeconds() - seconds) > 300)
    21 return Results.Unauthorized();
    22
    23 // The same algorithm the API uses: HMAC-SHA256 over "timestamp.body".
    24 using var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secret));
    25 var expected = "v1=" + Convert.ToHexString(
    26 hmac.ComputeHash(Encoding.UTF8.GetBytes($"{timestamp}.{body}"))).ToLowerInvariant();
    27
    28 if (!CryptographicOperations.FixedTimeEquals(Encoding.UTF8.GetBytes(expected), Encoding.UTF8.GetBytes(signature)))
    29 return Results.Unauthorized();
    30
    31 var deliveryId = request.Headers["X-uCRM-Event-Delivery"].ToString();
    32 // Record deliveryId, queue the work, then answer quickly.
    33 return Results.Ok();
    34});
    35
    36app.Run();
  5. 5
    Answer quickly with 2xxAny 2xx response marks the delivery as delivered. The API waits up to 30 seconds per attempt, so store the event and process it in the background. A 4xx or 5xx answer counts as a failure and is retried.
  6. 6
    Expect retriesFailed, timed-out or unreachable attempts are retried with growing waits of 1, 2, 4, 8 minutes and so on, capped at 120 minutes. After eight attempts the delivery stops and is kept as a dead letter. An endpoint that fails the outbound network policy, such as a private address, is stopped without retries. Pausing or deleting the webhook abandons its pending deliveries.
  7. 7
    Handle duplicatesA retry can arrive after your first attempt already succeeded, for example when your answer timed out. Store X-uCRM-Event-Delivery and skip deliveries you have processed. Use the payload id when several of your endpoints receive the same event.
  8. 8
    Rotate the secret safelyRoll secret issues a new secret for new deliveries. Deliveries queued before the roll keep the secret and endpoint they were queued with, so their retries are still signed with the old secret. During a rotation, accept either secret until those retries have finished.
  9. 9
    Confirm delivery end to endUse Send test event first: it reports the status code and duration, but test events aren't listed in the Delivery log. Then make a real change, such as creating a lead, and open Details: the log shows the event key, your response and the attempts.
NoteIf every signature fails, check that you hash the raw body (not re-serialized JSON), that you use the timestamp header from the same request, and that the secret is the latest one. A Failing status means recent attempts did not get a 2xx; read the response codes in the Delivery log. Dead-lettered deliveries are not resent automatically.

What happens next #

To act on an event, read the full record with the SDK in your background worker, keyed by the event's entityId: Your first read-only SDK call.

Was this article helpful?