Check the complete list of parameters and responses of the POST Emit event

What is an event?

A Customer Event is any action performed by a customer that can activate certain behavior-based campaigns. For instance, events can include actions like completing a purchase, submitting a survey, or registering on your platform.

You can send different types of events to Masivo, which will monitor them and apply your configured rules to distribute rewards through campaigns. However, only events that match the campaign’s specific criteria will successfully trigger those campaigns.

Emit an Event

When emitting an event, the customer, brand, and event type must be defined and included in the request. The other values are optional, depending on the nature of the event to be emitted.

const payload = {
  customer_id: "unique-customer-id",
  brand_id: "unique-brand-id",
  type: "PURCHASE",
  // Optional values
  order: {
    purchase_id: "unique-purchase-id",
    channel_id: "unique-channel-id",
    store_id: "unique-store-id",
    value: 20.95,
    discounted_value: 10.95,
    products: [
      {
        sku: "<string>",
        amount: 123,
        value: 123,
        discounted_value: 123,
        redeem: [
          {
            id: "3c90c3cc-0d44-4b50-8888-8dd25736052a",
            amount: 1,
          },
        ],
        tags: {},
        metadata: {},
      },
    ],
    shipping: {
      value: 3.25,
      discounted_value: 2.25,
      redeem: [
        {
          id: "3c90c3cc-0d44-4b50-8888-8dd25736052a",
          amount: 1,
        },
      ],
      tags: {},
      metadata: {},
    },
    payment_method: "CREDIT", "CREDIT" | "DEBIT"
    redeem: [
      {
        id: "3c90c3cc-0d44-4b50-8888-8dd25736052a",
        amount: 1,
      },
    ],
    metadata: {},
  },
  fulfilled: true,
  reserve: 1,
  redeem: [
    {
      id: "3c90c3cc-0d44-4b50-8888-8dd25736052a",
      amount: 1,
    },
  ],
  tags: {},
  metadata: {},
}

const response = await fetch("https://app.masivo.ai/api/storefront/v1/behavior/events", {
  method: "POST",
  headers: { Authorization: `Bearer ${accessToken}` },
  body: JSON.stringify(payload)
});

Fulfill an event

If the fulfilled attribute has been sent as false in the body of the POST Emit event endpoint, the event will be placed in a standby state. The reward won’t be added to the wallet until fulfilled is true.

It is important to note that when the event was not emitted with fulfill set to true, the rewards will not be redeemed until it is explicitly fulfilled.

It is also worth mentioning that the event will expire after 24 hours (by default depending on reserve value) if it has not been set to fulfill.

In this case, you will need to manually execute the fulfill if you want the event to be processed.

For this, it is necessary to send the event id of the event to the PATCH Fulfill event endpoint.

const response = await fetch(
  `https://app.masivo.ai/api/storefront/v1/behavior/events/${eventId}/fulfill`,
  {
    method: "PATCH",
    headers: { Authorization: `Bearer ${accessToken}` }
  }
);

After the event has been successfully fulfilled, The reward will be added to the wallet.

Reverse an event

If you want to reverse an event and all actions resulting from it, you must send the event id to the POST Reverse event endpoint, including a reason in the body of the request.

const payload = {
  reason: "<message>" // The reason why you are reversing the event
};

const response = await fetch(
  `https://app.masivo.ai/api/storefront/v1/behavior/events/${eventId}/reverse`,
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${accessToken}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify(payload)
  }
);

Once the event has been reversed, all accumulation, redemption, and updating of customer metrics will be reversed.

It is important to note that once an event has been reversed, its STATUS will change to "REVERSED".

What happens when an event expires?

An event expires when it’s hasn’t been sent with fulfill in true and it’s been 24 hours since that. The amount of days for expiration time can be extended by sending reserve in the body of the request.

What happens if the event is reversed when is still unfulfilled?

If an event is emitted with fulfill in false and then it is reversed, the event will be cancelled. The status in the response of the request will be set in "CANCELLED".

How reserves can be extended?

The reserve days can be extended by setting the reserve attribute in the body of the POST Emit event endpoint. So the value sent in reserve will be equal to the number of days the reserves will be extended.