# Notify an event

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Idempotency Supported](/docs/api/idempotency)

Use this API to notify Chargebee about important events that occur on your web pages, such as subscription cancellations. An event contains data about affected resources and additional details such as when the change occurred.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/hosted_pages/events \
     -u {site_api_key}:\
     -d event_name="CANCELLATION_PAGE_LOADED" \
     -d occurred_at=1435054328 \
     -d event_data='{"subscription_id":"__test__KyVnHhSBWmCoF2tJ"}'
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;
using ChargeBee.Models.Enums;
using Newtonsoft.Json.Linq;

ApiConfig.Configure("{site}","{site_api_key}");
var eventData = new JObject { ["subscription_id"] = "__test__KyVnHhSBWmCoF2tJ" };
EntityResult result = HostedPage.Events()
		.EventName(EventNameEnum.CancellationPageLoaded)
		.OccurredAt(1435054328)
		.EventData(eventData)
		.Request();
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    hostedpageAction "github.com/chargebee/chargebee-go/v3/actions/hostedpage"
    "github.com/chargebee/chargebee-go/v3/models/hostedpage"
    enum "github.com/chargebee/chargebee-go/v3/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := hostedpageAction.Events(&hostedpage.EventsRequestParams{
        EventName : enum.EventNameCancellationPageLoaded,
        OccurredAt : chargebee.Int64(1435054328),
        EventData : map[string]interface{}{
            "subscription_id" : "__test__KyVnHhSBWmCoF2tJ",
        },
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        fmt.Println(res)
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.HostedPageEventsRequest{
    EventName : chargebee.EventNameCancellationPageLoaded,
    OccurredAt : chargebee.Int64(1435054328),
    EventData : map[string]interface{}{
        "subscription_id" : "__test__KyVnHhSBWmCoF2tJ",
    },
}
  res, err := client.HostedPage.Events(req)
      if err != nil {
        fmt.Println(err)
    } else {
        fmt.Println(res)
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;
import java.sql.Timestamp;
import com.chargebee.org.json.JSONArray;
import com.chargebee.org.json.JSONObject;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = HostedPage.events()
            .eventName(EventName.CANCELLATION_PAGE_LOADED)
            .occurredAt(new Timestamp(1435054328L * 1000))
            .eventData(new JSONObject("{\"subscription_id\":\"__test__KyVnHhSBWmCoF2tJ\"}"))
            .request();

        HostedPage hostedPage = result.hostedPage();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.hostedPage.params.HostedPageEventsParams;
import com.chargebee.v4.models.hostedPage.responses.HostedPageEventsResponse;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

public class HostedPageEvents {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        HostedPageEventsParams params = HostedPageEventsParams.builder()
            .eventName(HostedPageEventsParams.EventName.CANCELLATION_PAGE_LOADED)
            .occurredAt(new Timestamp(1435054328L * 1000))
            .eventData(Map.of("subscription_id", "__test__KyVnHhSBWmCoF2tJ"))
            .build();

        HostedPageEventsResponse response = client.hostedPages().events(params);

        System.out.println(response);
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.hostedPage.events({
        event_name: "cancellation_page_loaded",
        occurred_at: 1435054328,
        event_data: {
            subscription_id: "__test__KyVnHhSBWmCoF2tJ"
        }
    });

    console.log(result);
    const hostedPage = result.hosted_page;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->hostedPage()->events([
    "event_name" => "cancellation_page_loaded",
    "occurred_at" => 1435054328,
    "event_data" => '{"subscription_id":"__test__KyVnHhSBWmCoF2tJ"}'
]);
$hostedPage = $result->hosted_page;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.HostedPage.events(
    cb_client.HostedPage.EventsParams(
        event_name=chargebee.EventName.CANCELLATION_PAGE_LOADED,
        occurred_at=1435054328,
        event_data={
            "subscription_id": "__test__KyVnHhSBWmCoF2tJ"
        }
    )
)
print(response)
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::HostedPage.events({
  :event_name => "CANCELLATION_PAGE_LOADED",
  :occurred_at => 1435054328,
  :event_data => {:subscription_id => "__test__KyVnHhSBWmCoF2tJ"}
})
```

## Sample Response

```json
{
  "success": true
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/hosted_pages/events

## Input Parameters

- `event_name` (required, enumerated string)
  The event that need to passed to a different system.
  Possible enum values:
    - `cancellation_page_loaded`
      Indicates native cancellation flow provided by the merchant is loaded rather than the retention flow.

- `occurred_at` (optional, timestamp(UTC) in seconds)
  Timestamp indicating when this event had occurred. .

- `event_data` (required, jsonobject)
  The meta data description of the event in key-value pair. The value is a JSON object with the following keys and their values.
  
  -   `subscription_id`: A unique and immutable identifier for the subscription. .

## Returns

- `success` (required, boolean)
  Event was processed successfully.
