# Save custom event

> Records a custom event for a profile: something that happens in your app, such as a completed
> onboarding. To start email sequences with the event, add its name to the entry rule of a
> [purpose](/docs/mail-purposes#event-triggers-from-your-app). To stop sequences early with the
> event, add its name to the exit rule of a purpose.
>
> Add the name before you send the event. Purpose rules only apply to events that Adapty Mail
> receives after you add the name.

## OpenAPI

```yaml
/api-specs/adapty-mail-api.yaml post /api/v1/profile/custom-event/save/
openapi: 3.1.0
info:
  title: Adapty Mail API
  version: 1.0.0
  description: |
    With the Adapty Mail API, you can [send user profiles, purchases, subscription changes, and custom events](/docs/mail-send-data-via-api)
    to Adapty Mail directly from your server.

    Use the API to:

    - Add subscribers when you don't have a base in Adapty Mail yet.
    - Reuse the subscriber base from your other apps.
    - Feed Adapty Mail server-to-server, with your backend as the source of truth.
    - Start and stop email sequences on events from your app, such as a completed onboarding.

    The [purpose](/docs/mail-purposes) of each flow decides which events start it. Of the eight
    purposes every project starts with, **Never purchased** by default only needs a profile with an
    email. The other standard marketing purposes need you to report purchases and subscription changes.
servers:
  - url: https://api-mail.adapty.io
    description: Production server
paths:
  /api/v1/profile/custom-event/save/:
    post:
      summary: Save custom event
      description: |
        Records a custom event for a profile: something that happens in your app, such as a completed
        onboarding. To start email sequences with the event, add its name to the entry rule of a
        [purpose](/docs/mail-purposes#event-triggers-from-your-app). To stop sequences early with the
        event, add its name to the exit rule of a purpose.

        Add the name before you send the event. Purpose rules only apply to events that Adapty Mail
        receives after you add the name.
      operationId: saveCustomEvent
      security:
        - apikeyAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CustomEventDTO"
            examples:
              basic:
                summary: A user completed onboarding
                value:
                  event_type: onboarding_completed
                  event_id: evt_def456
                  event_datetime: "2026-06-12T18:45:00Z"
                  external_profile_id: user_12345
                  payload:
                    goal: Sleep better
                    steps_completed: "6"
      responses:
        "200":
          description: |
            Custom event received. Adapty Mail applies purpose rules to the event after it responds, so
            the response doesn't show whether a sequence started. The response body is empty.
        "400":
          description: Validation failed — a required field is missing or invalid. `field_name` shows which field.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Errors"
              examples:
                default:
                  value:
                    errors:
                      - message: Field required
                        error_code: base_error
                        status_code: 400
                        field_name: event_type
        "403":
          description: Missing or invalid secret API key.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Errors"
              examples:
                default:
                  value:
                    errors:
                      - message: Secret key doesn't exist
                        error_code: secret_key_does_not_exist_error
                        status_code: 403
                        field_name: null
components:
  schemas:
    CustomEventDTO:
      type: object
      required:
        - event_type
        - event_id
        - event_datetime
        - external_profile_id
      properties:
        event_type:
          type: string
          pattern: ^[a-z][a-z0-9_]*$
          maxLength: 64
          description: |
            The event name, such as `onboarding_completed`. It has up to 64 characters: lowercase letters,
            digits, and underscores, with a letter first. Use the same name as under **Custom** in the
            entry rule or exit rule of a purpose.

            You can't give a custom event a name that Adapty Mail uses for its own events: `created`,
            `updated`, `email_confirmed`, `suppressed`, `deleted`, and every `event_type` of a
            transaction event, such as `subscription_started`.
        event_id:
          type: string
          minLength: 1
          maxLength: 128
          description: |
            Your unique identifier for this event. It has up to 128 characters. Adapty Mail ignores an
            `event_id` it already has, so you can safely retry a request.
        event_datetime:
          type: string
          format: date-time
          description: When the event happened, in ISO 8601 format, in UTC.
        external_profile_id:
          type: string
          description: |
            The same stable `external_profile_id` you send when you save the profile.

            You can send a custom event before the profile exists. When you later save a profile with
            the same identifier, Adapty Mail links the event to that profile.
            At that point, the profile can qualify for a purpose on the event.
        customer_user_id:
          type: string
          description: Identifier of the user in your own system.
        email:
          type: string
          format: email
          description: Email address of the user.
        source:
          type: string
        payload:
          type: object
          maxProperties: 50
          propertyNames:
            pattern: ^[a-z][a-z0-9_]*$
          additionalProperties:
            type: string
            maxLength: 1000
          description: |
            Data to show in emails. It can have up to 50 fields, and each value is a string of up to
            1,000 characters. Field names follow the character rules of `event_type`. Use the names that
            the purpose lists under **Payload fields**.

            Each field appears in emails through its
            [custom event placeholder](/docs/mail-email-data#custom-event-placeholders), such as
            `{{ custom_event.goal }}`.
    Errors:
      type: object
      description: Standard error response. Every failure returns a 4XX status with this shape.
      properties:
        errors:
          type: array
          items:
            type: object
            properties:
              message:
                type: string
                description: Human-readable description of the error.
              error_code:
                type: string
                description: Machine-readable error identifier.
              status_code:
                type: integer
                description: HTTP status code for this error.
              field_name:
                type: string
                description: The request field that caused the error, or `null` if the error isn't field-specific.
  securitySchemes:
    apikeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: |
        Authenticate every request with your Adapty Mail secret API key, sent as the **Authorization**
        header with the value `Bearer {your_secret_api_key}`, for example, `Bearer secret_live_...`.

        Find this key in Adapty Mail under **Settings**. The key is project-specific — it identifies the
        project the data belongs to, so the endpoints don't take a project ID.
```
