> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://sensorpro.crisp.help/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Sensorpro contact webhook

Sensorpro Native Webhooks

## Start here

Add contacts to Sensorpro with the Sensorpro contact webhook

To use the webhook we need an API Key.

Login to Sensorpro & navigate to Menu [API/API Keys]

## Get the API Key

Add a new API key

Title: Enter a title for the webhook.

Type: Select Sensorpro webhook from the dropdown.

Lock down by IP address: Set this to No.

Click OK

Your new API Key will show in the list.

Click on the green down-arrow to show the API Key & webhook link.

## Get the Webhook

1 Your Webhook link should now look like this:

```
https://apinie.sensorpro.net/api/WHContact/AddUpdateContact/d5e559a997
```

2 Use your webhook with the following options:

Method:
POST

Headers:
Content-Type: application/json

Body:

```
{   
   "AddToList": ["ListA"],
   "Contact": [
      {
         "FirstName": "Test First Name",
         "LastName": "Test Last Name",
         "PersonalEMail": "testemail@mycompany.com"
      }
   ],
   "UpdateByKey": "email",
   "SendWelcomeEmail": false,
   "SignupFormId":"00000000-0000-0000-0000-000000000000"
}
```

AddToList is an array. Make this a meaningful source name as you will be able to segment contacts based on this value in Sensorpro.

Optional.

If you would like to send a welcome email after the contact is added:

1. Set SendWelcomeEmail to True

2. Set SignupFormId from [Tools/Signupforms]

## Examples

#### PHP cURL

```
$url="https://apinie.sensorpro.net/api/WHContact/AddUpdateContact/d5e559a99";

$curl = curl_init();

$contact = array (
  'AddToList' => 
  array (
    0 => 'webhook'
  ),
  'Contact' => 
  array (
    0 => 
    array (
      'FirstName'     => $fname,
      'LastName'      => $lname,
      'PersonalEMail' => $email
    )
  ),
  'Options' => 
  array (
    'Parameters' => 
    array (
    ),
    'Action' => ''
  ),
  'ReturnFailedRequests' => false,
  'UpdateByKey'          => 'email',
  'SendWelcomeEmail' 	  => false,
  'SignupFormId' 	  => '00000000-0000-0000-0000-000000000000'
);

$c1 = json_encode($contact);

curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_POST => 1,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array("Content-Type: application/json"),
CURLOPT_POSTFIELDS => $c1
));

$response = curl_exec($curl);
$err = curl_error($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {

$r = array (
'Title'=>'Sensorpro',
'Contact'=>$email
);
$r1 = json_encode($r);
echo $r1;
```

## Checking Results

Monitor the status of your Webhook calls with

Menu [API/API inbound queue]

Select Sensorpro contact webhook, then the Log tab for Webhook call details:

Check that your contact was added with Menu [Contacts/All]
(Use the Filter/Search panel to search by email address)

Edit contact and check that the correct tag was applied:

## Optional: Using SHA256

Verify the webhook request by calculating a base64-encoded digital signature. This is calculated over the request body.

This signature is passed to the request in the header as:

X-HMAC-SHA256

1. To calculate the signature, use the shared secret on the API keys configuration. If this is blank, generate one.

> It is recommended that you remove any carriage returns or line feeds from the request body before generating the signature as the format of carriage returns and line feeds can vary between systems.

Code Examples of how to calculate signature:

C#:

```
string signature = "";
byte[] myKey = Encoding.UTF8.GetBytes(Secret);
byte[] myBody = Encoding.UTF8.GetBytes(Content);
using (HMACSHA256 hmac = new HMACSHA256(key: myKey))
{
      signature = Convert.ToBase64String(hmac.ComputeHash(myBody));
}
return signature;
```

PHP:

```
$calculated_hmac = base64_encode(hash_hmac('sha256', $myBody, SECRET, true));
```

> When the request is received the signature is calculated again using the shared secret and they must match for the request to be accepted.

Need help? Email us on [support@sensorpro.net](mailto:support@sensorpro.net)