Use of Dimension endpoints
How to use dimension endpoints in API
Creating a dimension
POST /v1/Dimensions
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.
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"
}
}
};
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.
_apiClient.Dimensions.CreateDimension(newDimension);
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
PUT /v1/Dimensions
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.
DimensionModel existingDimension = _apiClient.Dimensions.GetDimensions().Single(x => x.Alias == "Market");
The GetDimensions
method sends an HTTP request to the /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} 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.
_apiClient.Dimensions.UpdateDimension(existingDimension);
After modifying the existingDimension
, we update the PIM with the changes using the UpdateDimension
method, passing the object as an argument.
Last updated