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

# Create Activity

Use this endpoint to track an activity to LoyaltyLion. When tracking an activity, if an applicable rule exists, it will be triggered based on the name of the activity.

For the Clickthrough/Visit rule, you also need to specify the destination URL in the properties.

You shouldn't use this API to track and reward purchases. Instead you should use the [Orders API](/api-reference/v2/resources/orders/create-order) which allows you to send important information specific to orders, such as the order total and payment status.

<Info>
  If you're using the Activities API to award points for [custom activities](https://help.loyaltylion.com/en/articles/1965598-activity-custom), please note that only enrolled customers will receive points when they complete them.

  Guest customers are not eligible to earn points and **will not** receive those points retroactively after signing up to the program.
</Info>


## OpenAPI

````yaml /api-reference/v2/openapi.json POST /v2/activities
openapi: 3.1.1
info:
  title: LoyaltyLion Admin API
  version: v2
servers:
  - url: https://api.loyaltylion.com
security: []
tags:
  - name: identity
  - name: activities
  - name: orders
  - name: transactions
  - name: customers
  - name: webhooks
  - name: emails
  - name: sites
  - name: reviews
  - name: rewards
  - name: integrations
  - name: gatsby
paths:
  /v2/activities:
    post:
      tags:
        - activities
      operationId: activities.createActivity
      parameters:
        - name: site_id
          in: query
          description: >-
            Create the activity in the specified site. This is only required for
            programs that have multiple sites. Programs with only a single site
            can omit this parameter, and the activity will be created in the
            program's only site
          schema:
            type: number
      requestBody:
        description: Body
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ActivitiesCreateActivityRequestBody'
      responses:
        '201':
          description: '201'
        '400':
          $ref: '#/components/responses/ClientErrorBadRequest'
        '401':
          description: '401'
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                      details:
                        type: object
                        propertyNames:
                          type: string
                        additionalProperties:
                          type: string
                    required:
                      - message
                    additionalProperties: false
                required:
                  - error
                additionalProperties: false
        '403':
          description: '403'
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                      details:
                        type: object
                        propertyNames:
                          type: string
                        additionalProperties:
                          type: string
                    required:
                      - message
                    additionalProperties: false
                required:
                  - error
                additionalProperties: false
        '422':
          description: '422'
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
                additionalProperties: {}
      security:
        - ProgramApiKey:
            - write_customers
        - SiteTokenSecret: []
components:
  schemas:
    ActivitiesCreateActivityRequestBody:
      type: object
      properties:
        name:
          description: >-
            A built-in or custom activity rule name. If you’re tracking a custom
            rule, this should be the rule identifier; if you’re tracking a
            built-in activity, the name must be prefixed with a `$`, for
            example, `$signup`
          type: string
        customer_id:
          type:
            - number
            - string
          description: >-
            A unique ID for the customer involved in the activity. This should
            be your internal ID (from your ecommerce platform) for this customer
        customer_email:
          description: The email address for the customer
          type: string
        merchant_id:
          type:
            - string
            - 'null'
          description: >-
            A unique ID used to link this activity to an internal resource in
            your system. If provided, you can update the state of this activity
            later using the activity update endpoint
        properties:
          description: >-
            A set of properties for this rule. Some rules require certain
            properties to be set
          anyOf:
            - title: Clickthrough rule
              type: object
              properties:
                url:
                  type: string
              required:
                - url
              additionalProperties: false
            - title: Other rules
              type: object
              propertyNames:
                type: string
              additionalProperties: {}
        ip_address:
          description: >-
            The IP address of the customer involved in this activity. Used in
            combination with user_agent to track referrals
          type:
            - string
            - 'null'
        user_agent:
          description: >-
            The full user agent string of the customer involved in this
            activity. Used in combination with ip_address to track referrals
          type:
            - string
            - 'null'
        date:
          type:
            - string
            - 'null'
          description: >-
            The date this activity occurred, as an ISO 8601 timestamp. Defaults
            to now if not provided
          example: '2025-01-01T12:00:00Z'
        referral_id:
          description: A LoyaltyLion referral ID
          type:
            - string
            - 'null'
        tracking_id:
          description: A LoyaltyLion email tracking ID
          type:
            - string
            - 'null'
        guest:
          description: >-
            A boolean value indicating if the customer is a guest. The default
            is true
          default: true
          type:
            - boolean
            - 'null'
        state:
          deprecated: true
          description: >-
            This field is no longer supported and will be ignored. Tracked
            activities  will have an initial state according to the matching
            rule, which can be  configured in your LoyaltyLion admin
          type:
            - string
            - 'null'
      required:
        - name
        - customer_id
        - customer_email
      additionalProperties: false
  responses:
    ClientErrorBadRequest:
      description: Bad Request
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: object
                properties:
                  message:
                    type: string
                  details:
                    type: object
                    additionalProperties:
                      type: string
                required:
                  - message
            required:
              - error
  securitySchemes:
    ProgramApiKey:
      type: http
      scheme: bearer
      description: >-
        An API key linked to a Program in LoyaltyLion, with a set of permissions
        (scopes). API keys can be created manually, or acquired through an
        OAuth2 flow. The API key should be provided as a `Bearer` token in the
        `Authorization` header
    SiteTokenSecret:
      type: http
      scheme: basic
      description: >-
        [DEPRECATED] Authenticate using a LoyaltyLion site's `token` as
        username, and its `secret` as the password. This authentication method
        is deprecated and will be removed in future. Use the `ProgramApiKey`
        authentication method instead

````