# Webhooks(Real-time updates)

**Webhooks** allow you to get programmatic notifications from Pipeliner about changes to your data as they happen in real-time.&#x20;

Rather than quiring you to pull information via the API, webhooks will **push** information to your endpoint when the event happens.&#x20;

**Example:** When the webhook is registered on Account Creation, then when the Account is created Pipeliner sends to your specified URL the JSON with the body of the newly created Account.&#x20;

## Registering Webhooks&#x20;

Registering webhook means, that you are going to set a listener on an event if something happens. Take a look at the table below which events are supported

<table><thead><tr><th width="166.57734763345138">Entity Name</th><th>Event Name</th></tr></thead><tbody><tr><td>Account</td><td><p><strong>Account.*</strong></p><p><strong>Account.Create</strong><br><strong>Account.Update</strong><br><strong>Account.Delete</strong><br><strong>Account.DocumentLinked</strong><br><strong>Account.OwnerChanged</strong></p></td></tr><tr><td>Contact</td><td><p><strong>Contact.*</strong></p><p><strong>Contact.Create</strong><br><strong>Contact.Update</strong><br><strong>Contact.Delete</strong><br><strong>Contact.DocumentLinked</strong><br><strong>Contact.OwnerChanged</strong></p></td></tr><tr><td>Opportunity</td><td><strong>Opportunity.*</strong><br><strong>Opportunity.Create</strong><br><strong>Opportunity.Update</strong><br><strong>Opportunity.Delete</strong><br><strong>Opportunity.DocumentLinked</strong><br><strong>Opportunity.OwnerChanged</strong><br><strong>Opportunity.Move</strong> (when the sales step is changed)<br><strong>Opportunity.Lost</strong> (when the Opportunity is Archived/LOst)<br><strong>Opportunity.Won</strong> (when the opportunity was won)<br><strong>Opportunity.Qualify</strong> (when the opportunity was created from Lead - Qualified)</td></tr><tr><td>Lead</td><td><p><strong>Lead.*</strong><br><strong>Lead.Create</strong><br><strong>Lead.Update</strong><br><strong>Lead.Delete</strong><br><strong>Lead.DocumentLinked</strong><br><strong>Lead.OwnerChanged</strong></p><p><strong>Lead.Lost</strong> (when the lead was Archived/Lost)<br><strong>Lead.BackToLead</strong> (when the opportunity was reverted to Lead)</p></td></tr><tr><td>Task</td><td><strong>Task.*</strong><br><strong>Task.Create</strong><br><strong>Task.Update</strong><br><strong>Task.Delete</strong><br><strong>Task.DocumentLinked</strong><br><strong>Task.OwnerChanged</strong><br><strong>Task.Comment</strong></td></tr><tr><td>Email</td><td><strong>Email.*</strong><br><strong>Email.Create</strong><br><strong>Email.Update</strong><br><strong>Email.Delete</strong><br><strong>Email.DocumentLinked</strong></td></tr><tr><td>Appointment</td><td><strong>Appointment.*</strong><br><strong>Appointment.Create</strong><br><strong>Appointment.Update</strong><br><strong>Appointment.Delete</strong><br><strong>Appointment.DocumentLinked</strong><br><strong>Appointment.OwnerChanged</strong><br><strong>Appointment.Comment</strong></td></tr><tr><td>Product</td><td><p><strong>Product.*</strong></p><p><strong>Product.Create</strong></p><p><strong>Product.Update</strong></p><p><strong>Product.Delete</strong></p></td></tr><tr><td>Product Line Items (OpptyProductRelation)</td><td><strong>OpptyProductRelation.*</strong><br><strong>OpptyProductRelation.Create</strong><br><strong>OpptyProductRelation.Update</strong><br><strong>OpptyProductRelation.Delete</strong></td></tr><tr><td>Custom Entity (Records)</td><td><p><strong>CustomEntity.*</strong></p><p><strong>CustomEntity.Create</strong></p><p><strong>CustomEntity.Update</strong></p><p><strong>CustomEntity.Delete</strong></p><p><strong>CustomEntity.DocumentLinked</strong></p><p><strong>CustomEntity.OwnerChanged</strong></p></td></tr></tbody></table>

### Register the Webhook

Register a webhook by calling this Endpoint

{% openapi src="<https://3470708952-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFpjbhrh1xo0SPAbAc7Ny%2Fuploads%2FOlNVdYj1h5GSxQmLHAjz%2Fopenapi%20(1).json?alt=media&token=4be07353-5170-4a95-9100-4f16545d47b0>" path="/entities/Webhooks" method="post" %}
[openapi (1).json](https://3470708952-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFpjbhrh1xo0SPAbAc7Ny%2Fuploads%2FOlNVdYj1h5GSxQmLHAjz%2Fopenapi%20\(1\).json?alt=media\&token=4be07353-5170-4a95-9100-4f16545d47b0)
{% endopenapi %}

#### Required Fields

<table><thead><tr><th width="239.74159671426082">Required API field Name</th><th>Description</th></tr></thead><tbody><tr><td>insecure_ssl</td><td>false (Recommended)<br>If True, remote side ssl certificate will not be validated when delivering notifications.</td></tr><tr><td>events</td><td>See table above to see what events you can use</td></tr><tr><td>url</td><td>The Server URL where the Webhook body should be sent</td></tr><tr><td>options</td><td>Options are described below</td></tr></tbody></table>

**Webhook options**

<table><thead><tr><th>Option Name</th><th width="150">REST API format</th><th>Description</th></tr></thead><tbody><tr><td><strong>On Field change</strong></td><td>on-field-change</td><td>Use when you want to trigger a webhook only on specific fields changes (eg. Opportunity value was changed)</td></tr><tr><td><strong>Skipping webhooks</strong></td><td>skip_keys</td><td>You can specify list of strings under "skip_keys" key in options. Whenever you make an API request with header "Webhook-Skip-Key" equal to any of the specified skip keys, the Webhook will not be triggered. This can prevent a Webhook loop.<br><br><strong>Example:</strong> Insert into every header of your Post Request the information "my integration", so Pipeliner is not sending the webhooks back whenever the record is created/updated and the record was created by request with header "my integration"</td></tr><tr><td><strong>Expanding data of Linked entities</strong></td><td>related_entity</td><td>When you want to get data about related Entity.<br><br><strong>Example:</strong> You have webhook on Opportunity. When you receive data on the Opportunity, you would like to know information about all Product Line items on the Opportunity</td></tr><tr><td><strong>Api paremeters</strong></td><td>expand, load_only, filter, filter-op</td><td>You can use some of the <a href="api-parameters"><strong>API parameters</strong></a> to work with webhooks<br><br><strong>Example:</strong> You want to trigger Webhook only on Open Opportunities</td></tr><tr><td><strong>Webhook for Custom entity</strong></td><td>custom_entity_api_name</td><td>Use when you want to trigger Webhook on Custom entities. You have to add API names of required custom entities.</td></tr><tr><td><strong>Webhook throttling</strong></td><td>chunk_size</td><td><p>Default:100</p><p>Defines how much data should come in one request</p></td></tr><tr><td><strong>Webhook throttling delay</strong></td><td>chunk_delay</td><td><p>Default:0 </p><p>each chunk will be delayed by N * chunk_delay seconds, where N is index of chunk</p></td></tr></tbody></table>

**Example of Option parameters**

```json
{
    "custom_entity_api_name": [ "CE_Bid", "CE_Campaign" ],	
    "entity": {
        "Contact": {
            "expand": [
                "primary_account",
                "primary_contact",
                "task_relations.task"
            ],
            "load-only": [
                "id",
                "primary_account",
                "primary_contact.first_name",
                "task_relations.task"
            ],
            "filter": {
                "email1": [
                    "test@example.com",
                    "test@example.net"
                ],
                "email2": "test@example.com"
            },
            "filter-op": {
                "email1": "eq"
            }, 
            "on-field-change": [
                "email1"
            ]
        },
        "Account": {
            "filter": {
                "owner_id": [
                    "9900cce6-bcd6-412a-bcd1-1904556c949a"
                ]
            }
        }
    },
    "related_entity": {
        "expand": [
            "contact"
        ],
        "load-only": [
            "id",
            "contact"
        ]
    },
    "skip_keys": [
        "gmail_sync",
        "custom_integration"
    ]
}
```

### **Webhooks examples**

For testing our examples we are going to create a request bin when we will sent our webhooks. We are going to use this service <https://requestbin.com/>.&#x20;

#### **Trigger webhook when Account is created**

```json
POST 
{{baseUrl}}/entities/Webhooks
{
    "insecure_ssl": false,
    "url": "https://enrdznpu5i7jp.x.pipedream.net",
    "events": [
        "Account.Create"
    ],
    "options": {}
}
```

Once the webhook was registered go to the Application and create a new account. Then check the body of created Account in requestbin application.

#### **Trigger webhook on field change**

When the Opportunity fields `Opportunity value` or `closing_date` are updated on the Opportunity send notification

```json
POST 
{{baseUrl}}/entities/Webhooks
{
    "insecure_ssl": false,
    "url": "https://enrdznpu5i7jp.x.pipedream.net",
    "events": [
        "Opportunity.Update"
    ],
    "options": {
        "entity": {
            "Opportunity": {
                "on-field-change": ["closing_date", "value"]
            }
        }
    }
}
```

**Trigger webhook on filtered data**

Listen to notifications only when the Opportunity is Opened (not won or lost). When attribute `filter-op` is not defined Pipeliner automatically uses "eq" value to filter the results

```json
{
    "insecure_ssl": false,
    "url": "https://enrdznpu5i7jp.x.pipedream.net",
    "events": [
        "Opportunity.Update"
    ],
    "options": {
        "entity": {
            "Opportunity": {
                "filter":{
                    "status": "Open"
                }
            }
        }
    }
}
```

**Webhooks for Custom Entity records**

To use webhooks for custom entity, the attribute `custom_entity_api_name` should contain API names of required custom entities.

```json
{
    "insecure_ssl": false,
    "url": "https://enrdznpu5i7jp.x.pipedream.net",
    "events": [
        "CustomEntity.Create", 
	"CustomEntity.Update"
    ],
    "options": {
        "custom_entity_api_name": [ "CE_Bid", "CE_Campaign" ],
        "entity": {
            "CE_Bid": {
		"filter": {
		    "name": "important"
		},
		"filter-op": {
		    "name": "contains"
		}
	    }
        }
    }
}
```
