Magento API v2 and C# - set custom attributes whilst adding product

Magento API v2 and C# - set custom attributes whilst adding product

August 7, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento API v2 and C# - set custom attributes whilst adding product

Setting Custom Product Attributes via Magento API v2 in C#

As an experienced developer, I understand your challenge of setting custom product attributes while adding or updating products using Magento’s API v2 in C#. Let me guide you through the correct approach to achieve this.

Understanding the Current Issue

Firstly, let’s diagnose what might be going wrong with your current implementation:

associativeEntity AdditionalAttributes = new associativeEntity();
AdditionalAttributes.key = "my_price";
AdditionalAttributes.value = "12,33";

While you’re correctly setting the key as “my_price” and the value as a string, Magento’s API expects specific data formats for certain attribute types. The price attribute, in particular, requires decimal values.

Correcting the Value Format

To set a custom price attribute accurately, ensure you format the value as a decimal type:

associativeEntity AdditionalAttributes = new associativeEntity();
AdditionalAttributes.key = "my_price";
AdditionalAttributes.value = "12.33"; // Use decimal point instead of comma

Remember that for attributes with “Price” input types, you should use the standard decimal point notation (e.g., 12.33) rather than the European-style comma notation (12,33).

Ensuring Attribute Existence

Before attempting to set an attribute value, make sure the custom attribute exists and is assigned to the product’s attribute set.

You can verify this by checking if your “my_price” attribute is present in the catalog_product_entity_varchar or catalog_product_entity_decimal tables in your Magento database. If it doesn’t exist, you’ll need to create it using SQL or Magento’s admin interface.

Properly Handling API Calls

In your code:

handler.catalogProductCreate(session_id, "simple", attributeset_id, sku, mageProduct, "default");

Ensure the session is valid at the time of making the catalogProductCreate call. If the session has expired or was never properly established, the API will not accept your request.

Best Practices

For more advanced scenarios involving multiple attribute sets and complex product configurations:

  • Study Magento’s official documentation on product creation.
  • Use the appropriate API methods (like catalogProductUpdate) for updating existing products.
  • Handle exceptions and errors properly to ensure your application’s stability.

Remember, working with Magento’s APIs requires a deep understanding of both the e-commerce platform and your specific product configuration. Always double-check your attributes’ input types and values.

Conclusion

To set custom price attributes correctly in C# using Magento API v2:

  1. Use decimal point notation for “Price” type attributes.
  2. Verify attribute existence before setting values.
  3. Ensure a valid active session before making API calls.
  4. Follow the official documentation for advanced scenarios.

By following these guidelines, you should be able to successfully set your custom price attribute while adding or updating products via Magento API v2 in C#.

Catalog API Configuration Pricing

Our network