Creating or updating a product
Learn how to programmatically create or update a product using product identifiers (productId).
When creating or updating a product through our API or Global Commerce system, it's essential to understand the proper procedures and guidelines to ensure a smooth process and avoid potential errors. This guide will walk you through the necessary steps and provide important details, such as product variations, locale management, and correctly grouping attribute values. Following these guidelines will help you effectively manage your products and avoid common pitfalls.
Do not send multiple simultaneous requests to create or update a product via API and Global Commerce or Bulk Product Upload (BPU). Simultaneous changes to a product can lead to errors in the database.
When managing a product or a product's locale, note that:
Adding the
variations
object to the payload allows you to create a base product with variations. When you create a product without thevariations
object, it is an individual product. You cannot transfer an individual product to a base product programmatically. However, you can transfer an individual product to a base product from Global Commerce.The request automatically adds the
locales
object from the base product to each product variation. An error appears in the response if the locales are inconsistent between the base product and the product variations.If
en_GB
anden_US
exist in the base product and onlyen_US
exists in the product variation, this request copiesen_GB
to the product variation.If
en_GB
anden_US
exist in the base product andja_JP
exists in the product variation, the response returns an error.
The request updates the correct attribute value even if the attribute value is in the wrong group. For example, if you put the
eccn
attribute for export control in the storefront setting group, the request will update theeccn
attribute as long as the value is correct. However, the response will put the attribute in the export control group where it belongs.
Product payload example
Here is an example payload for creating or updating a product, including a base product with variations. This example demonstrates the necessary structure and key attributes you need to provide for a base product with variations:
The following payload example contains data attributes for a base product with variations. See the products resource for a description of the attributes.
When implementing this payload structure in your requests, you must modify the example values according to your specific product data.
When creating a product, you need to provide the following objects in the payload:
deploymentRequiredChanges
: This object is required for base or individual products.liveChanges
: This object is required for base or individual products.localization
: This object is required for base or individual products.variations
: This object is only required for a base product with product variations.
Creating an individual or base product
You can create the base product and its variations using one call. When doing so, the request copies the base product attributes to each product variation. You can update the attributes for a product variation by including the modified attributes in the product variation request payload.
The following POST /v1/products
request creates a base product with product variations.
When creating an individual or base product, you do not need to provide a productId
. The productId
will be provided when you create the product. If you want to use an ERID
, provide the ERID in the payload. Global Commerce will associate the created product with the given ERID. After associating the ERID with the product, you can continue to use the ERID in the call request when updating the product.
You can add the variations
object to the payload to create a base product with variations. When you create a product without the variations
object, it is an individual product.
To add a locale to a product, add the locale data in the payload using the POST /v1/products/{productid}
request.
The following example creates a new base product with a productId
and product variations using a variationProductId
. See the products resource for a description of the attributes.
An ERID request requires the x-erid-as-pid=true
header. The following example creates a new base product with an ERID
and product variations using an variationERID
. See the products resource for a description of the attributes.
Creating a digital product
The following example creates a digital product. See the products resource for a description of the attributes.
Product history attributes
To Date: The beginning of the search date range.
From Date: The end of the search date range.
Change Type: A brief description of the change applied to the product. Some of the possible change type values are as follows:
Copied: This indicates a user copied the current product from another product. When a user copies an existing product, the Product History page shows the product ID and the name of the original product on which the new product is based.
Revert: This indicates a user reverted the product to a previous version (and shows the previous version). For more about reverting a product, see Reverting changes to products.
Save or Save (Including Live Change): This indicates you or another user saved a change to the product. Save means you must deploy the product before shoppers can see the change in your store. Save (Live Change) indicates the system automatically applied the change to your store, and you do not need to deploy the product. You can click the plus (+) sign next to a save event to see additional information for that event. One or more of the following columns appear with every save event:
Locale: Indicates the locales where the change occurred.
Area: Indicates the general area in the editor where the change occurred. Example: If you change the name, the area lists "Storefront Settings" as the area where you can find the name.
Field: Displays the changed field. Example: You can use this field name and the content displayed in the Area column to locate the attribute in Global Commerce.
Old Value: Displays the old value. If a value is not present, no content appears in this column.
New Value: Displays the new value. Note: Save does not always mean the item changed. If you view the item and click the Save button without applying any changes, the system logs that change.
Status Changed to Deployed: Indicates the state of the product changed to the Live state. The changes now appear in your store.
Status Changed to Design: The product status changed to the Design state.
Status Changed to New: When you create a product, the product status changes to the New state.
Took Ownership: Indicates that a new user can edit a product. The name of the new user appears in the Modified By column. Ownership indicates the last person to edit the product. Another user cannot edit the product until they own it. Ownership prevents two users from editing the product at the same time.
Variation Added: A user added a variation to the product. The variation ID, as well as the varying attributes, also appear in the Change Type column.
Variation Deleted: A user deleted product variation. The variation ID, as well as the varying attributes, also appear in the Change Type column.
Product/Variation ID: Displays the product identifier or variation for the product.
If this is an individual product, only the product ID appears. If this is a base product, (Base) appears after the ID.
If this is a product variation, the name of the variation and the varying attributes (in parentheses) appear after the ID.
Modified By: The name of the person or application that last modified the product. API indicates the Admin API. For example,
jdoe
orAPI (ZDIOODJi***)
, wherejdoe
is the Global Commerce username andZDIOODJi***
is the first eight digits of the API key for an Admin API request.Modified On: The date and time when the product was last modified.
Adding or replacing a product's locale
You can localize your products so shoppers can see product information in their native language, date format, time format, and currency. You can also localize themes and styles to create a look and feel for a specific locale or region.
A locale is a designator that combines the two-letter ISO 639-1 language code with the ISO 3166-1 alpha-2 country code (such as en_US
). For example, the en_GB
language code represents the English language and the country of Great Britain.
When you create or update a product, you can configure the product to use those locales and enter localized content for that product. When choosing locales, note the following:
When you enter text for the product in the default locale, the same text appears for all supported locales until you either "override" or "specify" the default in a specific locale folder. You can override the default locales by adding a product variation after creating a base product. You can also specify the default locales when creating a base product and its variations simultaneously. Changing the product's default locale does not affect your store's global default locale settings.
You can provide localized content for a product. A
localizations
object appears for each supported locale where you can enter the localized information. You do not have to enter localized content for all supported locales.
The following example payload adds or replaces a product's locale. See the products resource for a description of the attributes.
By default, shoppers can purchase products in any locale (within defined export controls). You should restrict the purchasing products to only supported areas. See Limiting purchases to supported locales for more information.
Ideally, you should localize a product when you first create it. However, you can localize a product after you create and deploy it to your store. If you turn off the fields and options on a locale in Global Commerce, the supported locale uses the default locale setting. See Overriding the default locale for more information.
The following POST /v1/products/{productid}
request updates for an existing product by replacing attributes. You must provide either a productId
or ERID
.
Last updated