> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xtremepush.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Hit event

> Used to send a realtime event to Xtremepush when an event occurs on a backend system "sign_up", "purchase" etc, similar to the <code>eventHit</code> methods found in the web and mobile SDKs. This allows users to trigger campaigns/workflows based on events that happen outside of sites or Apps.

<br>

<p>The endpoint allows requests to update specific user attributes (both system and custom attributes such as <code>email</code>, <code>first name</code>, <code>mobile number</code>, etc.) before the event is hit. This ensures your event-triggered campaigns are sent to an up-to-date profile.</p>

<br>

<p><strong>Note:</strong> If your project does not have Consent Manager enabled, the <code>consent_preferences</code> object will be ignored.</p>

## OpenAPI

````json POST /hit/event
{
  "openapi": "3.1.0",
  "info": {
    "title": "external-api",
    "version": "1"
  },
  "servers": [
    {
      "url": "https://api.eu.xtremepush.com/api/external"
    }
  ],
  "paths": {
    "/hit/event": {
      "post": {
        "summary": "Hit event",
        "description": "Used to send a realtime event to Xtremepush when an event occurs on a backend system \"sign_up\", \"purchase\" etc, similar to the <code>eventHit</code> methods found in the web and mobile SDKs. This allows users to trigger campaigns/workflows based on events that happen outside of sites or Apps.\n\n<br>\n\n<p>The endpoint allows requests to update specific user attributes (both system and custom attributes such as <code>email</code>, <code>first name</code>, <code>mobile number</code>, etc.) before the event is hit. This ensures your event-triggered campaigns are sent to an up-to-date profile.</p>\n\n<br>\n\n<p><strong>Note:</strong> If your project does not have Consent Manager enabled, the <code>consent_preferences</code> object will be ignored.</p>",
        "operationId": "event-hit-event",
        "deprecated": "false",
        "requestBody": {
          "required": "true",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "apptoken",
                  "user_id",
                  "event"
                ],
                "properties": {
                  "apptoken": {
                    "type": "string",
                    "description": "Your App token"
                  },
                  "user_id": {
                    "type": "string",
                    "description": "Your external user ID. If a user with such user ID doesn't exist it will be automatically created."
                  },
                  "event": {
                    "type": "string",
                    "description": "Event name"
                  },
                  "value": {
                    "type": "string",
                    "description": "Can be: string / number, eg. `100`, or key-value object, eg. `{\"product\": \"Some Product\"}`"
                  },
                  "user_attributes": {
                    "type": "string",
                    "format": "json",
                    "description": "Key-value array of user attributes. These attributes will be updated before executing any event-triggered campaign. This is useful when the campaign depends on one of the user attributes, such as email address or first name."
                  },
                  "timestamp": {
                    "type": "string",
                    "format": "date-time",
                    "description": "The timestamp of the event. By default the timestamp will be read in UTC. If your project is in a different timezone, the timezone can be indicated in the timestamp: `2024-12-13 11:36:00 +01:00`."
                  },
                  "consent_preferences": {
                    "type": "string",
                    "format": "json",
                    "description": "Optional map of consent preferences by channel. Each channel key must contain a map of preferences with binary values to show their status (`1` for opt-in and `0` for opt-out). A metadata object can be included. To update consent preferences, ensure that Consent Manager is enabled for your project."
                  }
                }
              },
              "examples": {
                "Hit event with user attributes and consent preferences": {
                  "value": {
                    "apptoken": "YOUR_APPTOKEN",
                    "user_id": "USER_ID",
                    "event": "purchase",
                    "value": {
                      "product": "Some Product"
                    },
                    "user_attributes": {
                      "email": "user@example.com",
                      "first_name": "Sam"
                    },
                    "consent_preferences": {
                      "email": {
                        "marketing": "1"
                      },
                      "sms": {
                        "marketing": "0"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": "true",
                      "default": "true"
                    },
                    "code": {
                      "type": "integer",
                      "example": "200",
                      "default": "0"
                    }
                  }
                },
                "examples": {
                  "Result": {
                    "value": {
                      "success": "true",
                      "code": "200"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "400",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": "false",
                      "default": "true"
                    },
                    "code": {
                      "type": "integer",
                      "example": "400",
                      "default": "0"
                    },
                    "message": {
                      "type": "string",
                      "example": "General error information"
                    },
                    "errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "text": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "Result": {
                    "value": {
                      "success": "false",
                      "code": "400",
                      "message": "General error information",
                      "errors": [
                        {
                          "text": [
                            "Detailed information about the specific error"
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        },
        "tags": [
          "Event Methods"
        ]
      }
    }
  }
}
````

