.. _Webhook_MessageSignatureValidation: ###################################### Webhook - Message Signature Validation ###################################### A webhook server typically listens for messages sent to its endpoint. To ensure that the server processes only messages sent by the GW Cloud API and that a message was not tampered with, the handling process should validate the webhook signature before processing it further. The message contains a header **X-Api-Message-Signature**. The value of this header is a **hex digest of a HMAC-SHA256 hash** of: * The **X-Api-Message-Id** header * A **newline character** * The **X-Api-Timestamp** header * A **newline character** * The **json message** payload Example: :: x-api-message-signature sha256=cc8e51f368511bc134c75172a9a541cb74dd5a325fe90a5763fbf96d18ce1c13 To produce the hash, a secret key called the **webhook secret** is required. This secret is unique per integration project and is shared between Alphatronics and the software integrator. The code below shows the program code in C# to recalculate the message signature for an incoming message: .. code-block:: c# var x_api_timestamp = "2026-10-26T12:52:59.6267557Z"; var x_api_message_id = "49db27cb-ab2d-4067-af42-6e2252456d29"; var payload = """{"event":{"methodName":"receiveSmartCardReaderState","arguments":[{"smartCardReaderStates":[16],"smartCardType":0,"deviceId":"smartcardreader1","version":"1.0"}],"$type":300},"moduleId":"RestApiModule1","$type":2,"version":1,"createdUtc":"2026-10-26T12:52:59.5896064Z","reportedUtc":"2026-10-26T12:52:59.377Z","id":"bdbeea7e-47a2-4509-991a-aac220da6eff","assetId":"200000201"}"""; var stringToSign = x_api_message_id + "\n" + x_api_timestamp + "\n" + payload; string sha256Signature = ""; using (var hmac = new System.Security.Cryptography.HMACSHA256(webhookSecret)) { var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(stringToSign)); sha256Signature = Convert.ToHexString(hash).ToLowerInvariant(); } if(sha256Signature == x_api_message_signature.Replace("sha256=", "")) Console.WriteLine("Signature is valid"); else Console.WriteLine("Signature is invalid");