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

# Delete user token events

> Deletes all events related to the specified user token from events metrics and analytics.

The deletion is asynchronous, and processed within 48 hours.
To delete a personalization user profile, see `Delete a user profile` in the Personalization API.

**Required ACL:** `deleteObject`


## OpenAPI

````yaml specs/insights.yml delete /1/usertokens/{userToken}
openapi: 3.1.0
info:
  title: Insights API
  summary: >-
    The Insights API lets you collect events related to your search and
    discovery experience
  description: >
    Events represent user interactions with your app or website.

    They unlock powerful features, such as recommendations, personalization,
    smarter search results,

    and analytics that help you optimize your user experience.


    ## Client libraries


    Use Algolia's API clients, libraries, and integrations to collect events
    from your UI and send them to the Insights API.

    For more information, see [Algolia's
    ecosystem](https://www.algolia.com/doc/libraries).


    ## Base URLs


    The base URLs for making requests to the Insights API are:


    - `https://insights.us.algolia.io`

    - `https://insights.de.algolia.io`

    - `https//insights.algolia.io` (routes requests to the closest of the above
    servers, based on your geographical location)


    **All requests must use HTTPS.**


    ## Authentication


    Add these headers to authenticate requests:


    - `x-algolia-application-id`. Your Algolia application ID.

    - `x-algolia-api-key`. An API key with the necessary permissions to make the
    request.
      The required access control list (ACL) to make a request is listed in each endpoint's reference.

    You can find your application ID and API key in the [Algolia
    dashboard](https://dashboard.algolia.com/account/api-keys).


    ## Request format


    Request bodies must be JSON objects.


    ## Response status and errors


    Response bodies are JSON objects.

    Deleting a user token returns an empty response body with rate-limiting
    information as headers.


    Successful responses return `2xx` statuses. Client errors return `4xx`
    statuses. Server errors return `5xx` statuses.

    Error responses have a `message` property with more information.


    The Insights API doesn't validate if the event parameters such as
    `indexName`, `objectIDs`, or `userToken`,

    correspond to anything in the Search API. It just checks if they're
    formatted correctly.

    Check the [Events](https://dashboard.algolia.com/events/health) health
    section,

    whether your events can be used for Algolia features such as Analytics, or
    Dynamic Re-Ranking.


    ## Version


    The current version of the Insights API is version 1, indicated by the `/1/`
    in each endpoint's URL.
  version: 1.0.0
servers:
  - url: https://insights.{region}.algolia.io
    variables:
      region:
        description: The region where your Algolia application is hosted.
        enum:
          - us
          - de
        default: us
  - url: https://insights.algolia.io
security:
  - appId: []
    apiKey: []
tags:
  - name: events
    x-displayName: Events
    description: >-
      Events represent user interactions with your website or app. They include
      details like the event's name, type, a timestamp, or a user token.
  - name: usertokens
    x-displayName: User tokens
    description: |
      Delete events related to a specific user token.
externalDocs:
  url: https://www.algolia.com/doc/guides/sending-events/getting-started
  description: Events
paths:
  /1/usertokens/{userToken}:
    delete:
      tags:
        - usertokens
      summary: Delete user token events
      description: >
        Deletes all events related to the specified user token from events
        metrics and analytics.

        The deletion is asynchronous, and processed within 48 hours.

        To delete a personalization user profile, see `Delete a user profile` in
        the Personalization API.
      operationId: deleteUserToken
      parameters:
        - name: userToken
          in: path
          description: User token for which to delete all associated events.
          required: true
          schema:
            $ref: '#/components/schemas/userToken'
      responses:
        '204':
          description: No content.
          headers:
            x-ratelimit-limit:
              $ref: '#/components/headers/x-ratelimit-limit'
            x-ratelimit-remaining:
              $ref: '#/components/headers/x-ratelimit-remaining'
            x-ratelimit-reset:
              $ref: '#/components/headers/x-ratelimit-reset'
        '422':
          description: Unprocessable Entity.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EventsResponse'
        '429':
          description: >
            Too Many Requests. This operation is rate-limited. Check the
            `x-ratelimit-limit` and `x-ratelimit-reset` headers of the response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EventsResponse'
      x-codeSamples:
        - lang: csharp
          label: C#
          source: |-
            // Initialize the client
            var client = new InsightsClient(
              new InsightsConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION")
            );

            // Call the API
            await client.DeleteUserTokenAsync("test-user-1");
        - lang: dart
          label: Dart
          source: |-
            // Initialize the client
            final client = InsightsClient(
                appId: 'ALGOLIA_APPLICATION_ID',
                apiKey: 'ALGOLIA_API_KEY',
                region: 'ALGOLIA_APPLICATION_REGION');

            // Call the API
            await client.deleteUserToken(
              userToken: "test-user-1",
            );
        - lang: go
          label: Go
          source: >-
            // Initialize the client with your application region, eg.
            insights.ALGOLIA_APPLICATION_REGION

            client, err := insights.NewClient("ALGOLIA_APPLICATION_ID",
            "ALGOLIA_API_KEY", insights.US)

            if err != nil {
              // The client can fail to initialize if you pass an invalid parameter.
              panic(err)
            }


            // Call the API

            err = client.DeleteUserToken(client.NewApiDeleteUserTokenRequest(
              "test-user-1"))
            if err != nil {
              // handle the eventual error
              panic(err)
            }
        - lang: java
          label: Java
          source: >-
            // Initialize the client

            InsightsClient client = new InsightsClient("ALGOLIA_APPLICATION_ID",
            "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION");


            // Call the API

            client.deleteUserToken("test-user-1");
        - lang: javascript
          label: JavaScript
          source: >-
            // Initialize the client

            // Replace 'us' with your Algolia Application Region

            const client = algoliasearch('ALGOLIA_APPLICATION_ID',
            'ALGOLIA_API_KEY').initInsights({ region: 'us' });


            // Call the API

            await client.deleteUserToken({ userToken: 'test-user-1' });
        - lang: kotlin
          label: Kotlin
          source: |-
            // Initialize the client
            val client =
              InsightsClient(
                appId = "ALGOLIA_APPLICATION_ID",
                apiKey = "ALGOLIA_API_KEY",
                region = "ALGOLIA_APPLICATION_REGION",
              )

            // Call the API
            client.deleteUserToken(userToken = "test-user-1")
        - lang: php
          label: PHP
          source: >-
            // Initialize the client

            $client = InsightsClient::create('ALGOLIA_APPLICATION_ID',
            'ALGOLIA_API_KEY', 'ALGOLIA_APPLICATION_REGION');


            // Call the API

            $client->deleteUserToken(
                'test-user-1',
            );
        - lang: python
          label: Python
          source: >-
            # Initialize the client

            # In an asynchronous context, you can use InsightsClient instead,
            which exposes the exact same methods.

            client = InsightsClientSync(
                "ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION"
            )


            # Call the API

            client.delete_user_token(
                user_token="test-user-1",
            )
        - lang: ruby
          label: Ruby
          source: >-
            # Initialize the client

            client = Algolia::InsightsClient.create("ALGOLIA_APPLICATION_ID",
            "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION")


            # Call the API

            client.delete_user_token("test-user-1")
        - lang: scala
          label: Scala
          source: |-
            // Initialize the client
            val client = InsightsClient(
              appId = "ALGOLIA_APPLICATION_ID",
              apiKey = "ALGOLIA_API_KEY",
              region = Option("ALGOLIA_APPLICATION_REGION")
            )

            // Call the API
            Await.result(
              client.deleteUserToken(
                userToken = "test-user-1"
              ),
              Duration(100, "sec")
            )
        - lang: swift
          label: Swift
          source: >-
            // Initialize the client

            let client = try InsightsClient(appID: "ALGOLIA_APPLICATION_ID",
            apiKey: "ALGOLIA_API_KEY", region: .us)


            // Call the API

            try await client.deleteUserToken(userToken: "test-user-1")
        - lang: cURL
          label: curl
          source: |-
            curl --request DELETE \
              --url https://insights.us.algolia.io/1/usertokens/test-user-1 \
              --header 'x-algolia-api-key: ALGOLIA_API_KEY' \
              --header 'x-algolia-application-id: ALGOLIA_APPLICATION_ID'
components:
  schemas:
    userToken:
      type: string
      minLength: 1
      maxLength: 129
      pattern: '[a-zA-Z0-9_=/+-]{1,129}'
      description: >
        Anonymous or pseudonymous user identifier.


        Don't use personally identifiable information in user tokens.

        For more information, see [User
        token](https://www.algolia.com/doc/guides/sending-events/concepts/usertoken).
      example: test-user-1
    EventsResponse:
      type: object
      description: The response of the Insights API.
      additionalProperties: false
      properties:
        message:
          type: string
          description: Details about the response, such as error messages.
        status:
          type: integer
          description: The HTTP status code of the response.
  headers:
    x-ratelimit-limit:
      description: Number of allowed requests per one minute.
      example: 100
      schema:
        type: integer
    x-ratelimit-remaining:
      description: Number of remaining requests in the current period.
      example: 99
      schema:
        type: integer
    x-ratelimit-reset:
      description: >-
        Timestamp when the rate limit will reset, measured in seconds since the
        Unix epoch.
      example: 1710682486
      schema:
        type: integer
  securitySchemes:
    appId:
      type: apiKey
      in: header
      name: x-algolia-application-id
      description: Your Algolia application ID.
    apiKey:
      type: apiKey
      in: header
      name: x-algolia-api-key
      description: >
        Your Algolia API key with the necessary permissions to make the request.

        Permissions are controlled through access control lists (ACL) and access
        restrictions.

        The required ACL to make a request is listed in each endpoint's
        reference.

````