# Use of Dimension endpoints

### Creating a dimension

{% tabs %}
{% tab title="HTTP" %}
**POST** /v1/Dimensions
{% endtab %}

{% tab title="Request body (json)" %}

```
{
  "Uid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "Alias": "string",
  "Segments": [
    {
      "Uid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      "Identifier": "string",
      "Name": "string"
    }
  ]
}
```

{% endtab %}
{% endtabs %}

When creating a new dimension, we define each dimension through its alias, along with its segments and their identifiers and names. In the following example we will show how to set up an dimension with multiple segments. In this scenario, users need the flexibility to switch between market segment data for products within the PIM system, depending on the chosen market segment.

{% code title="C#" overflow="wrap" %}

```csharp
DimensionModel newDimension = new DimensionModel()
{
    Uid = Guid.NewGuid(),
    Alias = "Market",
    Segments = new List<DimensionSegmentModel>()
    {
        new DimensionSegmentModel
        {
            Uid = Guid.NewGuid(),
            Identifier = "Global",
            Name = "Global"
        },
        new DimensionSegmentModel
        {
            Uid = Guid.NewGuid(),
            Identifier = "Denmark",
            Name = "Denmark"
        },
        new DimensionSegmentModel
        {
            Uid = Guid.NewGuid(),
            Identifier = "USA",
            Name = "USA"
        }
    }
};
```

{% endcode %}

Start of with setting up the model with a unique ID (Uid) and an alias to identify the dimension. Then proceed to create the segments within the dimension, each with its own Uid, identifier, and name.

{% code title="C#" overflow="wrap" %}

```csharp
_apiClient.Dimensions.CreateDimension(newDimension);
```

{% endcode %}

Once everything is set up, we proceed to call the `CreateDimension` method, which sends an HTTP request to the `/v1/Dimensions` endpoint. The `newDimension` object, which we initialized earlier, is passed as an argument, allowing a dimension to be created in the PIM according to the specified parameters.

### Updating a dimension

{% tabs %}
{% tab title="HTTP" %}
**PUT** /v1/Dimensions
{% endtab %}

{% tab title="Request body (json)" %}

```
{
  "Uid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "Alias": "string",
  "Segments": [
    {
      "Uid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      "Identifier": "string",
      "Name": "string"
    }
  ]
}
```

{% endtab %}
{% endtabs %}

With the previous knowledge on how to create a new dimension we can follow up with a little larger example of how to update a dimension.

{% code title="C#" overflow="wrap" %}

```csharp
DimensionModel existingDimension = _apiClient.Dimensions.GetDimensions().Single(x => x.Alias == "Market");

```

{% endcode %}

The `GetDimensions` method sends an HTTP request to the [/v1/Dimensions](https://docs.struct.com/api-reference/endpoints/dimensions#get-v1-dimensions) endpoint. It returns a list of `DimensionModel`. We use `Single` to select the only dimension with the alias "Market".

Alternatively, you can use the [/v1/Dimensions/{uid}](https://docs.struct.com/api-reference/endpoints/dimensions#get-v1-dimensions-uid) endpoint if you know the specific uid of the dimension you would like to retrieve.

When modifying the data of the dimension, you wont be able to change the identifier since the name is dependent on the identifier.&#x20;

{% code title="C#" overflow="wrap" %}

```csharp
_apiClient.Dimensions.UpdateDimension(existingDimension);

```

{% endcode %}

After modifying the `existingDimension`, we update the PIM with the changes using the `UpdateDimension` method, passing the object as an argument.
