---
title: "Building an event request"
slug: "building-an-event-request"
abstract: "How to build an event request with examples."
---
# Building an event request

When the request configuration is complete, you can invoke the `Build()` method to get the request object.

```csharp
var eventRequest = UTRequestBuilder.EventWithDefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                                          .AddCustomValues("key1", "value1")
                                          .AddCustomValues("key2", "value2")
                                          .Timestamp(DateTime.Now)
                                          .Build();
```

When you build a request, you must observe the following rules:

- You can define optional parameters in any order.

    For example, the following two code samples are both correct requests:

    ```text
    UTRequestBuilder.SearchEvent("some keywords")
                    .DefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                    .Timestamp(DateTime.Now)
                    .AddCustomValues("key", "value")
                    .Build();
    ```
    ```text
    UTRequestBuilder.SearchEvent("some keywords")
                    .AddCustomValues("key", "value")
                    .Timestamp(DateTime.Now)
                    .DefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                    .Build();
    ```

- The `Add…` methods accumulate values, so you must consider the order in which you invoke them.

    For example, the following request will contain two custom values:

    ```text
    UTRequestBuilder.EventWithDefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                    .AddCustomValues("key1", "value1")
                    .AddCustomValues("key2", "value2")
                    .Build();
    ```

- Methods that do not accumulate values should only be invoked once.

    An example of a correct request:

    ```text
    UTRequestBuilder.SearchEvent("some keywords")
                    .DefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                    .Build();
    ```

    An example of an incorrect request that throws an *InvalidOperationException* exception:

    ```text
    UTRequestBuilder.SearchEvent("some keywords")
                    .DefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                    .DefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                    .Timestamp(DateTime.Now)
                    .Timestamp(DateTime.Now)
                    .Build();
    ```