Productsup
Attributes

Conditionally mandatory attributes

How to make an attribute mandatory only when another attribute has a specific value.

Many channels require an attribute only in specific cases. For example, a marketplace may require the attribute cell_composition only for products that contain batteries. A conditionally mandatory attribute covers this case: it stays optional by default and becomes mandatory only when all of its conditions are met.

Conditionally mandatory attributes are in beta. Selecting the Conditional type in the Developer Portal is available to beta users only, and the platform doesn't yet enforce the conditions in Dataflow and Data View.

How conditions work

Every conditionally mandatory attribute has at least one condition. A condition compares the value of another attribute of the same export template, called the trigger attribute, to a value you define:

SettingDescription
Trigger AttributeAnother attribute of the same export template whose value activates the condition. An attribute can't trigger itself
Operatorequals or not equals
Trigger ValueThe value the platform compares the trigger attribute's value to
DescriptionAn optional hint that tells users where to find or set the trigger attribute, for example, Product > Compliance > Batteries Required

When all conditions of an attribute are met, the attribute becomes mandatory. As long as at least one condition isn't met, the attribute stays optional.

Set an attribute as conditionally mandatory

To make an attribute conditionally mandatory in the Developer Portal, take these steps:

On the export template setup page, go to the section Attributes and analyzer tests, and select the name of the attribute you want to set up.

In Type, select Conditional. The Conditions Editor appears with one empty condition.

Set up the condition by choosing a Trigger Attribute, choosing an Operator, and entering a Trigger Value. You can also enter a Description to help users find the trigger attribute.

To add another condition, select Add Condition. The attribute becomes mandatory only when all conditions are met.

Select Save.

Your changes don't become available in the platform until you select Publish. See Publish export template changes.

Manage conditionally mandatory attributes via the API

Attributes in the Export Template Management API carry an optional type field with the values optional, mandatory, or conditionally_mandatory, plus a conditions array. The type field takes precedence over the legacy mandatory boolean when you send both.

This example makes an existing attribute conditionally mandatory:

curl -X PATCH "https://export-template-api.productsup.com/V1/export-templates/{templateId}/attributes/{attributeId}" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "conditionally_mandatory",
    "conditions": [
      {
        "triggerAttribute": "batteries_required",
        "triggerValue": "true",
        "operator": "equals",
        "description": "Product > Compliance > Batteries Required"
      }
    ]
  }'

Each condition accepts these fields:

FieldRequiredDescription
triggerAttributeYesThe name of another attribute of the same export template whose value activates the condition
triggerValueYesThe value the trigger attribute's value is compared to
operatorNoequals or not_equals. Defaults to equals
descriptionNoA human-readable hint that tells users where to find or set the trigger attribute

The API validates these rules:

  • An attribute with the type conditionally_mandatory needs at least one condition.
  • Attributes with the types optional and mandatory can't have conditions.
  • The trigger attribute must be an existing attribute of the same export template.
  • An attribute can't reference itself as a trigger attribute.

The same type and conditions fields are available when you create attributes via POST /V1/export-templates/{id}/attributes, when you use the bulk endpoints, and in the attributes array of POST /V2/export-templates. All endpoints that return attributes include the type and conditions fields in their responses.

How is this guide?

On this page