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

# Trigger event

> 
    Trigger event is the main (and only) way to send notifications to subscribers. The trigger identifier is used to match the particular workflow associated with it. Maximum number of recipients can be 100. Additional information can be passed according the body interface below.
    To prevent duplicate triggers, you can optionally pass a **transactionId** in the request body. If the same **transactionId** is used again, the trigger will be ignored. The retention period depends on your billing tier.

<Warning>
  Enter your API key in the `Authorization` field like the example shown below:

  E.g `ApiKey 18d2e625f05d80e`
</Warning>

<RequestExample>
  ```javascript Node.js theme={null}
  import { Novu } from '@novu/node';

  const novu = new Novu("<NOVU_API_KEY>");

  await novu.trigger('<WORKFLOW_TRIGGER_IDENTIFIER>',
    {
      to: {
        subscriberId: '<UNIQUE_SUBSCRIBER_IDENTIFIER>',
        email: 'john@doemail.com',
        firstName: 'John',
        lastName: 'Doe',
      },
      payload: {
        name: "Hello World",
        organization: {
          logo: 'https://happycorp.com/logo.png',
        },
      },
    }
  );
  ```

  ```php PHP theme={null}
  use Novu\SDK\Novu;

  $novu = new Novu(<NOVU_API_KEY>);

  $novu->triggerEvent([
      'name' => '<WORKFLOW_TRIGGER_IDENTIFIER>',
      'payload' => ['customVariables' => 'Hello'],
      'to' => [
          'subscriberId' => '<UNIQUE_SUBSCRIBER_IDENTIFIER>',
          'phone' => '07983882186'
      ]
  ])->toArray();
  ```

  ```bash cURL theme={null}

  curl -X POST https://api.novu.co/v1/events/trigger \
    -H "Authorization: ApiKey <NOVU_API_KEY>" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "<WORKFLOW_TRIGGER_IDENTIFIER>",
      "to": {
        "subscriberId": "<UNIQUE_SUBSCRIBER_IDENTIFIER>",
        "email": "john@doemail.com",
        "firstName": "John",
        "lastName": "Doe"
      },
      "payload": {
        "name": "Hello World",
        "organization": {
          "logo": "https://happycorp.com/logo.png"
        }
      }
    }'
  ```

  ```ruby Ruby theme={null}
  require 'novu'

  client = Novu::Client.new('<NOVU_API_KEY>')

  payload = {
      'name' => '<WORKFLOW_TRIGGER_IDENTIFIER>',
      'payload' => { # optional
          'first-name' => 'Adam' # optional
      },
      'to' => {
          'subscriberId' => '<UNIQUE_SUBSCRIBER_IDENTIFIER>'
      },
      'transactionId' => '89kjfke9893' #optional
  }

  client.trigger_event(payload)
  ```

  ```go Go theme={null}
  package main

  import (
  	"context"
  	"fmt"
  	novu "github.com/novuhq/go-novu/lib"
  	"log"
  )

  func main() {
  	subscriberID := "<UNIQUE_SUBSCRIBER_IDENTIFIER>"
  	apiKey := "<NOVU_API_KEY>"
  	eventId := "<WORKFLOW_TRIGGER_IDENTIFIER>"

  	ctx := context.Background()
  	to := map[string]interface{}{
  		"lastName":     "Doe",
  		"firstName":    "John",
  		"subscriberId": subscriberID,
  		"email":        "john@doemail.com",
  	}

  	payload := map[string]interface{}{
  		"name": "Hello World",
  		"organization": map[string]interface{}{
  			"logo": "https://happycorp.com/logo.png",
  		},
  	}

  	data := novu.ITriggerPayloadOptions{To: to, Payload: payload}
  	novuClient := novu.NewAPIClient(apiKey, &novu.Config{})

  	resp, err := novuClient.EventApi.Trigger(ctx, eventId, data)

  	if err != nil {
  		log.Fatal("novu error", err.Error())
  		return
  	}
  }
  ```

  ```python Python theme={null}
  from novu.api import EventApi

  url = "https://api.novu.co"
  api_key = "<NOVU_API_KEY>"

  novu = EventApi(url, api_key).trigger(
      name="<WORKFLOW_TRIGGER_IDENTIFIER>",  # This is the Workflow ID. It can be found on the workflow page.
      recipients="<UNIQUE_SUBSCRIBER_IDENTIFIER>", # The subscriber ID can be gotten from the dashboard.
      payload={},  # Your custom Novu payload goes here
  )
  ```

  ```java Java theme={null}
  import co.novu.common.base.Novu;
  import co.novu.api.common.SubscriberRequest;
  import co.novu.api.events.requests.TriggerEventRequest;
  import co.novu.api.events.responses.TriggerEventResponse;

  public class Main {
      public static void main(String[] args) {
          String apiKey = "<NOVU_API_KEY>";

          Novu novu = new Novu(apiKey);

          SubscriberRequest subscriberRequest = new SubscriberRequest();
          subscriberRequest.setEmail("<EMAIL_ADDRESS>");
          subscriberRequest.setFirstName("<FIRST_NAME>");
          subscriberRequest.setLastName("<LAST_NAME>");
          subscriberRequest.setPhone("<PHONE_NUMBER>");
          subscriberRequest.setAvatar("<AVATAR>");
          subscriberRequest.setSubscriberId("<SUBSCRIBER_ID>");

          TriggerEventRequest triggerEventRequest = new TriggerEventRequest();
          triggerEventRequest.setName("<NAME>");
          triggerEventRequest.setTo(subscriberRequest);
          triggerEventRequest.setPayload(Collections.singletonMap("<CUSTOM_VARIABLE_NAME>", "<CUSTOM_VARIABLE_VALUE>"));
          
          TriggerEventResponse response = novu.triggerEvent(triggerEventRequest);
      }
  }
  ```

  ```csharp .NET theme={null}
  using Novu.DTO;
  using Novu.Models;
  using Novu;

  var novuConfiguration = new NovuClientConfiguration
  {
      /** 
      * Defaults to https://api.novu.co/v1 
      */
      Url = "https://novu-api.my-domain.com/v1", 
      ApiKey = "12345",
  };

  var novu = new NovuClient(novuConfiguration);

  public class OnboardEventPayload
  {
    [JsonProperty("username")]
    public string Username { get; set; }

    [JsonProperty("welcomeMessage")]
    public string WelcomeMessage { get; set; }
  }

  var onboardingMessage = new OnboardEventPayload
  {
    Username = "jdoe",
    WelcomeMessage = "Welcome to novu-dotnet"
  };

  var payload = new EventTriggerDataDto()
  {
    EventName = "onboarding",
    To = { SubscriberId = "subscriberId" },
    Payload = onboardingMessage
  };

  var trigger = await novu.Event.Trigger(payload);
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
      "data": {
          "acknowledged": true,
          "status": "processed",
          "transactionId": "string"
      }
  }
  ```
</ResponseExample>

<Accordion title="Idempotent nature of transactionId">
  The `transactionId` within Novu is a unique identifier that is used to ensure the idempotent nature of notification delivery.

  When you trigger an event to send a notification, you have the option to provide a `transactionId`. If you do not provide one, Novu will generate a UUID for you.

  **This identifier is particularly useful for preventing the same notification from being sent multiple times in case the trigger event is inadvertently called more than once.**

  By leveraging the `transactionId`, you can make idempotent requests, which means if the same `transactionId` is used in another request, Novu's API will recognize it and will not send the same notification again.

  <Note>
    This upholds the principle of idempotency, ensuring that the effect of the operation is the same, no matter how many times the request is repeated with the same `transactionId`.
  </Note>
</Accordion>


## OpenAPI

````yaml post /v1/events/trigger
openapi: 3.0.0
info:
  title: Novu API
  description: >-
    Novu REST API. Please see https://docs.novu.co/api-reference for more
    details.
  version: '1.0'
  contact:
    name: Novu Support
    url: https://discord.gg/novu
    email: support@novu.co
  termsOfService: https://novu.co/terms
  license:
    name: MIT
    url: https://opensource.org/license/mit
servers:
  - url: https://api.novu.co
  - url: https://eu.api.novu.co
security: []
tags:
  - name: Events
    description: >-
      Events represent a change in state of a subscriber. They are used to
      trigger workflows, and enable you to send notifications to subscribers
      based on their actions.
    externalDocs:
      url: https://docs.novu.co/workflows
  - name: Subscribers
    description: >-
      A subscriber in Novu represents someone who should receive a message. A
      subscriber’s profile information contains important attributes about the
      subscriber that will be used in messages (name, email). The subscriber
      object can contain other key-value pairs that can be used to further
      personalize your messages.
    externalDocs:
      url: https://docs.novu.co/subscribers/subscribers
  - name: Topics
    description: >-
      Topics are a way to group subscribers together so that they can be
      notified of events at once. A topic is identified by a custom key. This
      can be helpful for things like sending out marketing emails or notifying
      users of new features. Topics can also be used to send notifications to
      the subscribers who have been grouped together based on their interests,
      location, activities and much more.
    externalDocs:
      url: https://docs.novu.co/subscribers/topics
  - name: Notification
    description: >-
      A notification conveys information from source to recipient, triggered by
      a workflow acting as a message blueprint. Notifications can be individual
      or bundled as digest for user-friendliness.
    externalDocs:
      url: https://docs.novu.co/getting-started/introduction
  - name: Integrations
    description: >-
      With the help of the Integration Store, you can easily integrate your
      favorite delivery provider. During the runtime of the API, the
      Integrations Store is responsible for storing the configurations of all
      the providers.
    externalDocs:
      url: https://docs.novu.co/channels-and-providers/integration-store
  - name: Layouts
    description: >-
      Novu allows the creation of layouts - a specific HTML design or structure
      to wrap content of email notifications. Layouts can be manipulated and
      assigned to new or existing workflows within the Novu platform, allowing
      users to create, manage, and assign these layouts to workflows, so they
      can be reused to structure the appearance of notifications sent through
      the platform.
    externalDocs:
      url: https://docs.novu.co/content-creation-design/layouts
  - name: Workflows
    description: >-
      All notifications are sent via a workflow. Each workflow acts as a
      container for the logic and blueprint that are associated with a type of
      notification in your system.
    externalDocs:
      url: https://docs.novu.co/workflows
  - name: Notification Templates
    description: >-
      Deprecated. Use Workflows (/workflows) instead, which provide the same
      functionality under a new name.
  - name: Workflow groups
    description: Workflow groups are used to organize workflows into logical groups.
  - name: Changes
    description: >-
      Changes represent a change in state of an environment. They are analagous
      to a pending pull request in git, enabling you to test changes before they
      are applied to your environment and atomically apply them when you are
      ready.
    externalDocs:
      url: >-
        https://docs.novu.co/platform/environments#promoting-pending-changes-to-production
  - name: Environments
    description: >-
      Novu uses the concept of environments to ensure logical separation of your
      data and configuration. This means that subscribers, and preferences
      created in one environment are never accessible to another.
    externalDocs:
      url: https://docs.novu.co/platform/environments
  - name: Inbound Parse
    description: >-
      Inbound Webhook is a feature that allows processing of incoming emails for
      a domain or subdomain. The feature parses the contents of the email and
      POSTs the information to a specified URL in a multipart/form-data format.
    externalDocs:
      url: https://docs.novu.co/platform/inbound-parse-webhook
  - name: Feeds
    description: >-
      Novu provides a notification activity feed that monitors every outgoing
      message associated with its relevant metadata. This can be used to monitor
      activity and discover potential issues with a specific provider or a
      channel type.
    externalDocs:
      url: https://docs.novu.co/activity-feed
  - name: Tenants
    description: >-
      A tenant represents a group of users. As a developer, when your apps have
      organizations, they are referred to as tenants. Tenants in Novu provides
      the ability to tailor specific notification experiences to users of
      different groups or organizations.
    externalDocs:
      url: https://docs.novu.co/tenants
  - name: Messages
    description: >-
      A message in Novu represents a notification delivered to a recipient on a
      particular channel. Messages contain information about the request that
      triggered its delivery, a view of the data sent to the recipient, and a
      timeline of its lifecycle events. Learn more about messages.
    externalDocs:
      url: https://docs.novu.co/workflows/messages
  - name: Organizations
    description: >-
      An organization serves as a separate entity within your Novu account. Each
      organization you create has its own separate integration store, workflows,
      subscribers, and API keys. This separation of resources allows you to
      manage multi-tenant environments and separate domains within a single
      account.
    externalDocs:
      url: https://docs.novu.co/platform/organizations
  - name: Execution Details
    description: >-
      Execution details are used to track the execution of a workflow. They
      provided detailed information on the execution of a workflow, including
      the status of each step, the input and output of each step, and the
      overall status of the execution.
    externalDocs:
      url: https://docs.novu.co/activity-feed
externalDocs:
  description: Novu Documentation
  url: https://docs.novu.co
paths:
  /v1/events/trigger:
    post:
      tags:
        - Events
      summary: Trigger event
      description: |2-

            Trigger event is the main (and only) way to send notifications to subscribers. 
            The trigger identifier is used to match the particular workflow associated with it. 
            Additional information can be passed according the body interface below.
            
      operationId: EventsController_trigger
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TriggerEventRequestDto'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TriggerEventResponseDto'
        '409':
          description: >-
            The request could not be completed due to a conflict with the
            current state of the target resource.
          content:
            application/json:
              schema:
                type: string
                example: >-
                  Request with key 3909d656-d4fe-4e80-ba86-90d3861afcd7 is
                  currently being processed. Please retry after 1 second
        '429':
          description: 'The client has sent too many requests in a given amount of time. '
          content:
            application/json:
              schema:
                type: string
                example: API rate limit exceeded
        '503':
          description: >-
            The server is currently unable to handle the request due to a
            temporary overload or scheduled maintenance, which will likely be
            alleviated after some delay.
          content:
            application/json:
              schema:
                type: string
                example: Please wait some time, then try again.
      security:
        - api-key: []
      x-codeSamples:
        - lang: typescript
          label: EventsController_trigger
          source: |-
            import { Novu } from "@novu/api";
            import { TopicPayloadDtoType } from "@novu/api/models/components";

            const novu = new Novu({
              apiKey: "<YOUR_API_KEY_HERE>",
            });

            async function run() {
              const result = await novu.trigger({
                name: "workflow_identifier",
                payload: {},
                overrides: {},
                to: [
                    {
                      topicKey: "topic_key",
                      type: TopicPayloadDtoType.Topic,
                    },
                ],
              });

              // Handle the result
              console.log(result)
            }

            run();
components:
  schemas:
    TriggerEventRequestDto:
      type: object
      properties:
        name:
          type: string
          description: >-
            The trigger identifier of the workflow you wish to send. This
            identifier can be found on the workflow page.
          example: workflow_identifier
        payload:
          type: object
          description: >-
            The payload object is used to pass additional custom information
            that could be used to render the workflow, or perform routing rules
            based on it. 
                  This data will also be available when fetching the notifications feed from the API to display certain parts of the UI.
          example:
            comment_id: string
            post:
              text: string
        overrides:
          type: object
          description: This could be used to override provider specific configurations
          example:
            fcm:
              data:
                key: value
        to:
          type: array
          description: The recipients list of people who will receive the notification.
          items:
            oneOf:
              - $ref: '#/components/schemas/SubscriberPayloadDto'
              - type: string
                description: Unique identifier of a subscriber in your systems
                example: SUBSCRIBER_ID
              - $ref: '#/components/schemas/TopicPayloadDto'
        transactionId:
          type: string
          description: >-
            A unique identifier for this transaction, we will generated a UUID
            if not provided.
        actor:
          description: >-
            It is used to display the Avatar of the provided actor's subscriber
            id or actor object.
                If a new actor object is provided, we will create a new subscriber in our system
                
          oneOf:
            - type: string
              description: Unique identifier of a subscriber in your systems
            - $ref: '#/components/schemas/SubscriberPayloadDto'
        tenant:
          description: |-
            It is used to specify a tenant context during trigger event.
                Existing tenants will be updated with the provided details.
                
          oneOf:
            - type: string
              description: Unique identifier of a tenant in your system
            - $ref: '#/components/schemas/TenantPayloadDto'
      required:
        - name
        - to
    TriggerEventResponseDto:
      type: object
      properties:
        acknowledged:
          type: boolean
          description: If trigger was acknowledged or not
        status:
          enum:
            - error
            - trigger_not_active
            - no_workflow_active_steps_defined
            - no_workflow_steps_defined
            - processed
            - subscriber_id_missing
            - no_tenant_found
          type: string
          description: Status for trigger
        error:
          description: In case of an error, this field will contain the error message
          type: array
          items:
            type: string
        transactionId:
          type: string
          description: Transaction id for trigger
      required:
        - acknowledged
        - status
    SubscriberPayloadDto:
      type: object
      properties:
        subscriberId:
          type: string
          description: >-
            The internal identifier you used to create this subscriber, usually
            correlates to the id the user in your systems
        email:
          type: string
        firstName:
          type: string
        lastName:
          type: string
        phone:
          type: string
        avatar:
          type: string
          description: An http url to the profile image of your subscriber
        locale:
          type: string
        data:
          type: object
        channels:
          type: array
          items:
            $ref: '#/components/schemas/SubscriberChannelDto'
      required:
        - subscriberId
    TopicPayloadDto:
      type: object
      properties:
        topicKey:
          type: string
          example: topic_key
        type:
          enum:
            - Subscriber
            - Topic
          type: string
          example: Topic
      required:
        - topicKey
        - type
    TenantPayloadDto:
      type: object
      properties:
        identifier:
          type: string
        name:
          type: string
        data:
          type: object
    SubscriberChannelDto:
      type: object
      properties:
        integrationIdentifier:
          type: string
        providerId:
          type: object
        credentials:
          $ref: '#/components/schemas/ChannelCredentialsDto'
      required:
        - providerId
        - credentials
    ChannelCredentialsDto:
      type: object
      properties:
        webhookUrl:
          type: string
        deviceTokens:
          type: array
          items:
            type: string
  securitySchemes:
    api-key:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        API key authentication. Allowed headers-- "Authorization: ApiKey
        <api_key>".

````