# Requests

Webhook data is sent as JSON in the POST request body to your configured endpoints.

The JSON payload has three root keys:

1. `object` represents the object that triggered the event (an affiliate, campaign, conversion, commission, etc.). The object's JSON structure will be identical to the structure returned by the REST API endpoints for that object type.
2. `event` contains metadata about the webhook event.
3. `request` contains metadata about this specific request to your endpoint.

## Example payload

Webhook payloads sent to your endpoint contain these top-level items:

| Key       | Description                                                                                |
| --------- | ------------------------------------------------------------------------------------------ |
| `object`  | A JSON representation of the record (Affiliate, Commission, etc) that triggered the event. |
| `event`   | Metadata about the event itself.                                                           |
| `request` | Metadata about this specific request.                                                      |

Below is an example of the JSON that would be posted to your endpoint for the `affiliate.confirmed` event, i.e. when an affiliate has successfully confirmed their email address.

```javascript
{
  "object": {
    "id": "3433fffa-8255-4843-81b1-22aebc21eb34",
    "first_name": "James",
    "last_name": "Bond",
    "email": "james@mi6.co.uk",
    "created_at": "2019-06-24T00:43:36.097Z",
    "updated_at": "2019-06-27T18:38:41.684Z",
    "referrals": 42,
    "conversions": 3,
    "confirmed_at": "2019-06-24T00:43:36.095Z",
    "links": [{
      "id": "81bf1128-0ba1-4c1c-835c-286521f8791a",
      "url": "http://www.demo.com:8080/?via=james",
      "token": "james",
      "referrals": 42,
      "conversions": 3
    }],
    "campaign": {
      "id": "82f26208-778e-4e98-a467-6ee264cf96d5",
      "name": "Friends of Acme",
      "created_at": "2019-06-24T00:43:35.985Z",
      "updated_at": "2019-06-24T00:43:35.985Z"
    },
    "paypal_email": null,
    "sign_in_count": 0,
    "stripe_account_id": null,
    "unconfirmed_email": null,
    "stripe_customer_id": null,
    "paypal_email_confirmed_at": null,
    "receive_new_commission_notifications": true
  },
  "event": {
    "id": "7fcdc81d-996a-4b7b-8faf-1db98b9d5507",
    "type": "affiliate.confirmed",
    "created_at": "2019-07-11T05:25:43.940Z",
    "api_version": "v1"
  },
  "request": {
    "id": "66a94f49-2b36-403c-83b8-91677cb1f460"
  }
}
```

## Responses, Errors, and Retries

When your endpoint receives and successfully processes a webhook event, your web server should return a `200` response code.

{% hint style="danger" %}
Any response code from your endpoint other than a `200` will be interpreted as a failure.
{% endhint %}

If a webhook fails, Rewardful will continue to attempt delivery over the next 3 days using exponential backoff. This means if the failures continue, we'll wait longer and longer between retries, before finally giving up after 3 days.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.rewardful.com/webhooks/requests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
