# SharinPix Webhooks

## Enrich image data through Webhooks

### What is a Webhook?

A WebHook is a callback request (HTTP POST) made to a specific URL when something happens.

In our case, we have these configurable Webhooks available:

* New image
* Processed image
* New publication
* New tag image
* Delete image
* Delete tag image
* Upload done

These callbacks can be configured on the admin page, in the Webhooks section. You can provide the URL on which you want the Webhook (callback) to occur.

{% hint style="danger" %}
Please note that the **New einstein prediction** event has been deprecated and should not be activated.
{% endhint %}

{% hint style="success" %}
**Tip**:

For more information on those events and how they are triggered, refer to the following article: [Types of SharinPix Events](https://docs.sharinpix.com/documentation/integrations/events/types-of-sharinpix-events)
{% endhint %}

{% hint style="warning" %}
**Note:**

1\. In order to use Webhooks, you should ensure that you have granted API access to SharinPix on your organization. To verify this, go to the **SharinPix Settings** tab and check if the second row, that is, **Sharinpix -> Salesforce full API access**, is highlighted in green.

In case the row, **Sharinpix -> Salesforce full API access** is still highlighted in red, simply click on the **Grant** button to grant API access.

For more detailed information on how to grant API access, please refer the the following article:

[Basic Setup - Step 2 - Register your Salesforce organization to SharinPix](https://docs.sharinpix.com/documentation/getting-started-with-sharinpix/basic-setup/basic-setup-step-2-register-your-salesforce-organization-to-sharinpix)

2\. All Webhooks of type **apex\_method** make use of Salesforce API and should be used only when needed.
{% endhint %}

![](https://2221230591-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5EvYRrLbUyvRh8o1jmMG%2Fuploads%2Fgit-blob-a03095c95f725555a15058326a453915c117a970%2Fsharinpix%20\(1\)%20\(2\).png?alt=media)

### Types of webhooks

1. [Call to URL with JSON payload using HTTP POST](#call-to-url-with-json-payload-using-http-post)
2. [Call to a static method in an Apex class](#call-to-a-static-method-in-an-apex-class)

To configure a webhook along with its endpoint url, access the Admin Dashboard and follow the instructions below.

### Call to URL with JSON payload using HTTP POST

* Select the ‘**Webhooks** ’ menu item from the navigation bar.
* Click on the ‘**New Webhook** ’ button.
* Enter the relevant details for the Webhook.

![](https://2221230591-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5EvYRrLbUyvRh8o1jmMG%2Fuploads%2FEV5PkRjhvErC5CDuTnFP%2Fimage%20\(53\).png?alt=media\&token=ffdda107-2cdf-4234-ac1c-9433d0f059d6)

### Call to a static method in an Apex class

In this case, we will use another type of webhook which will execute a static method on your Salesforce environment. The sample code below illustrates an example method which is called by a webhook.

```apex
public class Webhook {
    public static void perform(string payload, string webhookInformation){
        // your business logic here
    }
}
```

* **payload** is the json string containing the relevant actions.
* **webhookInformation** contains information about the webhook such as the event type.

Next:

1. Go to the SharinPix Administration dashboard.
2. Click on the **Webhooks** menu followed by the **New Webhook** button.
3. Select **apex\_method** as the *Action type* and insert the class name and method name.
4. Then, select the desired event.
5. Click on **Update V2** to save the configuration.

![](https://2221230591-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5EvYRrLbUyvRh8o1jmMG%2Fuploads%2FtF4jONZZR39M2bz1hHwj%2Fimage%20\(54\).png?alt=media\&token=a74d9ca5-f3c2-41ab-88e7-357ec587d8be)
