Receive and verify CRM webhook events
On this page
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 #
- 1Know what each request containsEvery delivery is a POST with a JSON body (
application/json) and these headers:Header Meaning X-uCRM-Event-DeliveryDelivery id; the same across retries. Test events send testX-uCRM-Event-TimestampUnix time in seconds when this attempt was signed X-uCRM-Signaturev1=followed by a lowercase hexadecimal HMAC-SHA256X-uCRM-Event-Testtrueon test events only - 2Read 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,occurredAtUtcandcreatedAtUtc.changedFieldsis a list of objects withfield,previousValueandnewValue. Fields that don't apply are null. A test event is synthetic:eventKeyiswebhook.test,testistrueanddataholds a message. - 3Pick the eventsA webhook with no events ticked receives every event. Examples from the catalogue:
Area Event keys Leads crm.lead_created,crm.lead_updated,crm.lead_status_changed,crm.lead_convertedContacts, companies, deals crm.contact_created,crm.account_created,crm.deal_created,crm.deal_stage_changedProposals, invoices crm.proposal.viewed,crm.proposal.accepted,crm.invoice_created,crm.invoice_paidBookings, tasks, projects crm.booking_confirmed,crm.booking_cancelled,crm.task_completed,crm.project_createdForms marketing.form_submitted,marketing.list_subscribedThe Events list in the Add webhook dialog shows the full catalogue for your workspace.
- 4Verify the signatureBuild the string
timestamp.bodyfrom theX-uCRM-Event-Timestampvalue, a dot and the raw body. Compute HMAC-SHA256 over it with the whole signing secret (UTF-8, includingucrm_whsec_) as the key, encode it as lowercase hex and prefixv1=. Compare it withX-uCRM-Signaturein constant time.A complete ASP.NET Core receiver (
Program.csof aMicrosoft.NET.Sdk.Webproject on .NET 10):1using System.Security.Cryptography;2using System.Text;34var builder = WebApplication.CreateBuilder(args);5var app = builder.Build();67app.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();1213 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 store16 if (string.IsNullOrEmpty(secret)) return Results.StatusCode(StatusCodes.Status500InternalServerError);1718 // 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();2223 // 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();2728 if (!CryptographicOperations.FixedTimeEquals(Encoding.UTF8.GetBytes(expected), Encoding.UTF8.GetBytes(signature)))29 return Results.Unauthorized();3031 var deliveryId = request.Headers["X-uCRM-Event-Delivery"].ToString();32 // Record deliveryId, queue the work, then answer quickly.33 return Results.Ok();34});3536app.Run(); - 5Answer 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.
- 6Expect 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.
- 7Handle duplicatesA retry can arrive after your first attempt already succeeded, for example when your answer timed out. Store
X-uCRM-Event-Deliveryand skip deliveries you have processed. Use the payloadidwhen several of your endpoints receive the same event. - 8Rotate 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.
- 9Confirm 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?