# Webhook.construct_event()

> Verify the signature, then return the parsed event envelope.

Source: https://docs.tryyoursize.com/reference/python/webhook-construct-event/

*Method* · `tryyoursize`

Verify the signature, then return the parsed event envelope.

```python
@staticmethod
def construct_event(payload: Union[bytes, str], sig_header: str, secret: str, tolerance: int = DEFAULT_TOLERANCE, now: Optional[int] = None) -> WebhookEvent
```

## Parameters

- **`payload`** (`Union[bytes, str]`, required): The raw request body (bytes or str), never re-serialized JSON.
- **`sig_header`** (`str`, required): The `TYS-Signature` header.
- **`secret`** (`str`, required): The endpoint's signing secret (`whsec_…`).
- **`tolerance`** (`int`, optional, default `DEFAULT_TOLERANCE`): Accepted age in seconds (either direction); 0 disables the check.
- **`now`** (`Optional[int]`, optional, default `None`): Overrides the clock (unix seconds), for tests.

## Returns

`WebhookEvent`: The event envelope (`id`, `type`, `api_version`, `created`, `mode`, `store_id`, `data`).

## Errors

`SignatureVerificationError`.

## Example

**Python**

```python
from flask import Flask, request

@app.post("/webhooks/tryyoursize")
def webhook():
    try:
        event = tryyoursize.Webhook.construct_event(
            request.get_data(), request.headers.get("TYS-Signature", ""), os.environ["TYS_WEBHOOK_SECRET"]
        )
    except tryyoursize.SignatureVerificationError:
        return "", 400
    if event["type"] == "garment.published":
        print(event["data"]["product_skus"])
    return "", 200
```

**Node.js**

```ts

app.post("/webhooks/tryyoursize", express.raw({ type: "application/json" }), (req, res) => {
  let event;
  try {
    event = tys.webhooks.constructEvent(req.body, req.headers["tys-signature"], process.env.TYS_WEBHOOK_SECRET!);
  } catch {
    return res.sendStatus(400);
  }
  if (event.type === "garment.published") console.log(event.data.product_skus);
  res.sendStatus(200);
});
```

## See also

- [Webhooks guide](https://docs.tryyoursize.com/guides/webhooks.md)
