# Webhooks / Custom

# Custom Webhooks

## Integration Revoked

- Event: INTEGRATION_REVOKED

This fires when a vendor revokes access to your application via the Integration Marketplace

The payload of the event is structured as:
```json
{
    "vendor" : {
        "id" : "vendor-id",
        "name": "vendor-name", 
        "url": "vendor-subdomain" 
    },
    "user": {
        "id": "user-id",
        "name": "user-name"
    }
}
```

## Outlet Created

- Event: OUTLET_CREATED

This fires when a new outlet is created in a vendor

The payload of the event is structured as:
```json
{
    "outlet": {
        "id": "outlet-id",
        "name": "outlet-name"
    },
    "vendor" : {
        "id" : "vendor-id",
        "name": "vendor-name", 
        "url": "vendor-subdomain" 
    }
}
```

## Outlet Deleted

- Event: OUTLET_DELETED

This fires when an outlet is deleted from a vendor

The payload of the event is structured as:
```json
{
    "outlet": {
        "id": "outlet-id",
        "name": "outlet-name"
    },
    "vendor" : {
        "id" : "vendor-id",
        "name": "vendor-name", 
        "url": "vendor-subdomain" 
    }
}
```

## Register Created

- Event: REGISTER_CREATED

This fires when a new register is created in a vendor

The payload of the event is structured as:
```json
{
    "register": {
        "id": "register-id",
        "name": "register-name"
    },
    "outlet": {
        "id": "outlet-id",
        "name": "outlet-name"
    },
    "vendor" : {
        "id" : "vendor-id",
        "name": "vendor-name", 
        "url": "vendor-subdomain" 
    }
}
```

## Register Deleted

- Event: REGISTER_DELETED

This fires when register is deleted from a vendor

The payload of the event is structured as:
```json
{
    "register": {
        "id": "register-id",
        "name": "register-name"
    },
    "outlet": {
        "id": "outlet-id",
        "name": "outlet-name"
    },
    "vendor" : {
        "id" : "vendor-id",
        "name": "vendor-name", 
        "url": "vendor-subdomain" 
    }
}
```

## Customers Merged

- Event: CUSTOMERS_MERGED

This fires when two or more Shopfront customers are merged into one

The payload of the event contains the following fields:

| Field   | Type                                                  | Description                                                   |
|---------|-------------------------------------------------------|---------------------------------------------------------------|
| results | [Customer](/documentation/Objects/Customers#Customer) | The Shopfront customer that was created from the merge        |
| merged  | Array                                                 | An array containing the Shopfront IDs of the merged customers |

## Inventory Updated

- Event: INVENTORY_UPDATED

This fires whenever a product's stock level has been updated (e.g. An invoice was received)

The payload of the event contains the [Product](/documentation/Objects/Products#Product)

The event body's `context` field contains information detailing the cause of change

### Context

The context object in the event body contains the following fields

| Field      | Type                                         | Description                                             |
|------------|----------------------------------------------|---------------------------------------------------------|
| changeType | [ChangeType](#inventory-updated-change-type) | The event that caused the product's inventory to change |
| changeId   | string                                       | The Shopfront ID of the event that occurred             |

### Change Type

The `changeType` can be any one of the following:

| Type       | Description                                              | Change ID Refers To                                                                    |
|------------|----------------------------------------------------------|----------------------------------------------------------------------------------------|
| SALE       | A sale was processed (either a completed or voided sale) | The ID of the [Sale](/documentation/Objects/Sales#Sale)                                |
| ORDER      | An order was received                                    | The ID of the received [Order](/documentation/Objects/Orders#Order)                    |
| STOCKTAKE  | A stocktake was applied                                  | The ID of the [Stocktake](/documentation/Objects/Stocktake#Stocktake)                  |
| STOCKTAKER | An external stocktake was applied                        | The ID of the [External Stocktake](/documentation/Objects/Stocktake#ExternalStocktake) |

## Bulk Inventory Updated

- Event: BULK_INVENTORY_UPDATED

Like [Inventory Updated](#inventory-updated), this fires whenever a product's stock level has been updated (e.g. An 
invoice was received)

If multiple product's stock level is modified by a single action, such as a completed stocktake, then all of these 
modified stock levels will be contained in this event.

The payload of the event is structured as:
```json
{
    "payload" : [
      {
        "outlet": "11f015d3835d409a89e6fe434e2b0081",
        "product": "11f05556c61ec328930a3b6dac65d65c",
        "caseQuantity": 4,
        "newQuantity": 24
      },
      {
        ...
      }
    ]
}
```

### Payload

The payload of the event contains the following fields.

| Field        | Type   | Description                                                         |
|--------------|--------|---------------------------------------------------------------------|
| outlet       | string | The ID of the outlet that had the inventory change                  |
| product      | string | The ID of the product with the inventory change                     |
| caseQuantity | float  | The number of items in a 'case' of this product.                    |
| newQuantity  | float  | The inventory level (stock level) of the product after modification |

## Order Attachment Uploaded

- Event: ORDER_ATTACHMENT_UPLOADED

This fires when an attachment is uploaded to an existing order, the order can be of any status.

The payload of this event is structured as:
```json
{
    "order": "order-id",
    "id": "attachment-id",
    "url": "https://url-to-attachment"
}
```

## Order Attachment Deleted

- Event: ORDER_ATTACHMENT_DELETED

This fires when an attachment is deleted from an existing order, the order can be of any status.

The payload of this event is structured as:
```json
{
    "order": "order-id",
    "id": "attachment-id",
    "url": "https://url-to-attachment"
}
```