Skip to main content

Managing PIM product variants

You can manage PIM product variants programmatically, including setting their availability, price, and SKU. This article explains how to perform these operations using the BackOffice API.

Using the API

Before you start, ensure your app has the necessary credentials to make API calls:

  1. In your tenant, go to Settings > External apps and register your app.
  2. Implement authentication in your app as described in the Authorization article.

C# API Client

To use the C# API client, initialize it with the required configuration:

var httpClient = new HttpClient();
var backOfficeApiConfiguration = new Aurigma.BackOfficeApi.ApiClientConfiguration()
{
ApiUrl = BACKOFFICE_API_URL,
AuthorizationToken = AUTH_TOKEN
};
var productsApiClient = new ProductsManagementApiClient(backOfficeApiConfiguration, httpClient);

Managing PIM Product Variants

To manage PIM product variants:

  1. Retrieve the list of all product variants.
  2. Set the price, availability, and SKU for the variants.

Example

// Get all product variants
var productVariants = await productsApiClient.GetProductVariantsAsync(tenantId: TENANT_ID, id: PRODUCT_ID);

// Set product variants price
await productsApiClient.SetProductVariantPriceAsync(
tenantId: TENANT_ID,
id: PRODUCT_ID,
body: new SetProductVariantPriceDto()
{
Items = new List<ProductVariantPriceDto>()
{
new ProductVariantPriceDto()
{
Price = 10.0,
VariantUIDs = productVariants.Items.Select(x => x.Uid).ToList()
}
}
});

// Set product variants availability
await productsApiClient.SetProductVariantAvailabilityAsync(
tenantId: TENANT_ID,
id: PRODUCT_ID,
body: new SetProductVariantAvailabilityDto()
{
Items = new List<ProductVariantAvailabilityDto>()
{
new ProductVariantAvailabilityDto()
{
Availability = false,
VariantUIDs = productVariants.Items.Select(x => x.Uid).ToList()
}
}
});

// Set product variants SKU
await productsApiClient.SetProductVariantSkuAsync(
tenantId: TENANT_ID,
id: PRODUCT_ID,
body: new SetProductVariantSkuDto()
{
Items = productVariants.Items
.Select(x => new ProductVariantSkuDto()
{
Sku = $"{x.Sku} v2",
VariantUIDs = [x.Uid]
})
.ToList()
});
important

The SetProductVariantPriceAsync, SetProductVariantAvailabilityAsync, and SetProductVariantSkuAsync methods force the product to create a new version. After calling these methods, you need to retrieve the updated variants again if you want to use their IDs.

Was this page helpful?