[Yandex Cloud documentation](../../../../index.md) > [Yandex Serverless Integrations](../../../index.md) > [Step-by-step guides](../../index.md) > EventRouter > Sending events to a bus > Sending events using a connector

# Sending events to a bus using a connector

## Timer {#timer}

To [send](../../../concepts/eventrouter/sending-events.md) events to a [bus](../../../concepts/eventrouter/bus.md) using a connector with a [Timer](../../../concepts/eventrouter/connector.md#timer) source, specify in the connector settings the data to send to the bus when the timer triggers.

## Connector for the EventRouter API {#er-api}

{% note info %}

You can send events to a bus using a connector for the EventRouter API only if there is at least one [rule](../../../concepts/eventrouter/rule.md) attached to that bus.

{% endnote %}

To send events to a bus using a [connector](../../../concepts/eventrouter/connector.md#from-api) with an EventRouter API source:

{% list tabs group=instructions %}

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. View the description of the [CLI command](../../../../cli/cli-ref/serverless/cli-ref/eventrouter/send-event.md) to send events to a bus using a connector for the EventRouter API:

      ```bash
      yc serverless eventrouter send-event --help
      ```
  1. Get a list of connectors:
     
     ```bash
     yc serverless eventrouter connector list
     ```
     
     Result:
     
     ```text
     +----------------------+-----------------------+----------------------+----------------------+---------+---------------------+
     |          ID          |         NAME          |        BUS ID        |      FOLDER ID       | STATUS  | DELETION PROTECTION |
     +----------------------+-----------------------+----------------------+----------------------+---------+---------------------+
     | f66g4h59ih2g******** | connector-my-ydb-flow | f66qn4p7uk6p******** | b1g681qpemb4******** | STOPPED | true                |
     | f66g6jcnc5no******** | yds-via-cli           | f66qn4p7uk6p******** | b1g681qpemb4******** | RUNNING | false               |
     | f66jfhcg1u71******** | mq-via-terraform      | f66qn4p7uk6p******** | b1g681qpemb4******** | RUNNING | false               |
     +----------------------+-----------------------+----------------------+----------------------+---------+---------------------+
     ```
  1. Send an event to a bus using the connector you selected:

      ```bash
      yc serverless eventrouter send-event \
        --name <connector_name> \
        --event '<event>' \
        --file <file_path>
      ```

      Where:
      * `--name`: Name of the connector you are using to send the event to the bus.
      
          Instead of name, you can provide the connector's ID in the `--id` parameter.
      * `--event`: Event in [JSON](https://en.wikipedia.org/wiki/JSON) format, e.g., `{"name": "value"}`.

      * `--file`: Path to the file containing the event or batch of events in JSON format.

          You can use the `--file` parameter to send to the bus either one event or several events at the same time by specifying them in the command as a JSON array, e.g., `[{"name1": "value1"},{"name2": "value2"}]`.

      The `--event` and `--file` parameters are mutually exclusive: you can use only one of them.

- API {#api}

  Use the [EventService/Send](../../../eventrouter/api-ref/grpc/Event/send.md) gRPC API call to send an event to a bus using a connector for the EventRouter API:

  1. If you do not have the gRPCurl utility installed, [install](https://github.com/fullstorydev/grpcurl) it.
  1. If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../../cli/quickstart.md#install).
  1. Get an [IAM token](../../../../iam/concepts/authorization/iam-token.md) used for [authentication](../../../api-ref/eventrouter/authentication.md) in the API.

      ```bash
      IAM_TOKEN=$(yc iam create-token)
      ```

      The command will save the IAM token to the `IAM_TOKEN` variable.
  1. Get a list of connectors:
     
     ```bash
     yc serverless eventrouter connector list
     ```
     
     Result:
     
     ```text
     +----------------------+-----------------------+----------------------+----------------------+---------+---------------------+
     |          ID          |         NAME          |        BUS ID        |      FOLDER ID       | STATUS  | DELETION PROTECTION |
     +----------------------+-----------------------+----------------------+----------------------+---------+---------------------+
     | f66g4h59ih2g******** | connector-my-ydb-flow | f66qn4p7uk6p******** | b1g681qpemb4******** | STOPPED | true                |
     | f66g6jcnc5no******** | yds-via-cli           | f66qn4p7uk6p******** | b1g681qpemb4******** | RUNNING | false               |
     | f66jfhcg1u71******** | mq-via-terraform      | f66qn4p7uk6p******** | b1g681qpemb4******** | RUNNING | false               |
     +----------------------+-----------------------+----------------------+----------------------+---------+---------------------+
     ```
  1. Create a file with the request body, e.g., `body.json`:

      ```json
      {
        "connector_id": "<connector_ID>",
        "message": <event_or_array_of_events>
      }
      ```

      Where:
      * `connector_id`: ID of the connector you are using to send the event to the bus.
      * `message`: Event in [JSON](https://en.wikipedia.org/wiki/JSON) format, e.g., `"{\"name\": \"value\"}"`.

          You can send to the bus either one event or several or several events at the same time by specifying them in the `message` field as a JSON array, e.g., `["{\"name1\": \"value1\"}","{\"name2\": \"value2\"}"]`.
  1. Run a gRPC call by specifying the path to the `body.json` file you created earlier:

      ```bash
      grpcurl \
        -rpc-header "Authorization: Bearer $IAM_TOKEN" \
        -d @ < body.json \
        events.eventrouter.serverless.yandexcloud.net:443 yandex.cloud.serverless.eventrouter.v1.EventService/Send
      ```

{% endlist %}

## Connector for Yandex Data Streams {#yds}

Events get to the bus from a [data stream](../../../../data-streams/concepts/glossary.md#stream-concepts) through a connector with a [Yandex Data Streams](../../../../data-streams/index.md) source. 

## Connector for Yandex Message Queue {#ymq}

Events get to the bus from a [message queue](../../../../message-queue/concepts/queue.md) through a connector with a [Yandex Message Queue](../../../../message-queue/index.md) source.