Creating a Product with a Price Using the Public API
Introduction
This guide explains how to use the CRM's public API to create a product and assign it a price. The API allows you to build your product catalog programmatically, supporting both simple products and products with multiple variants.
Understanding Product Types
Before creating a product, it's important to understand the two main types you can create in the CRM.
Products with Price
This is a standard product without variations, such as a single poster size. It has one price and one set of details.
Products with Variants
This type of product has multiple variations, like a t-shirt available in different colors and sizes. Each unique combination of options (e.g., Red, Small) can have its own price.
API Authorization
To use the public API, you must first authenticate your requests. You will need a valid access token. For detailed steps on obtaining authorization, please refer to the official API documentation on authorization.
Creating a Product
The first step is to create the product itself using the Create a Product API endpoint.
Required Properties
When making your API request, you must include the following key properties in the payload:
- name: The name of the product.
- locationId: The ID of the sub-account where the product will be created.
- description: A description of the product.
- productType: The type of product, such as PHYSICAL or DIGITAL.
- image: The URL for the product's primary image.
- availableInStore: A boolean (true or false) indicating if the product should be available in e-commerce stores.
- medias: An array of media objects for the product. Each object requires an id, title, url, type (currently only 'image'), and isFeatured flag.
- variants: (For variant products only) An array of variant classifications (e.g., Color, Size). Each variant requires an id, name, and an options array. Each option within the array requires its own id and name.
Example: Product with a Single Price
Here is an example payload for creating a simple product without variants.
{
"name": "High Speed Memory Drive",
"description": "A high speed memory drive with latest safety features and breath taking design",
"locationId": "<sub-account_ID>",
"availableInStore": true,
"productType": "PHYSICAL",
"image": "https://via.placeholder.com/150",
"medias": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"title": "High Speed Memory Drive",
"url": "https://via.placeholder.com/150",
"type": "image",
"isFeatured": true
}
]
}
Example: Product with Variants
Here is an example payload for creating a product with multiple variants.
{
"name": "T-shirt",
"description": "Latest t-shirt with latest design and quality",
"locationId": "<sub_account_id>",
"availableInStore": true,
"productType": "PHYSICAL",
"image": "https://via.placeholder.com/150",
"medias": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"title": "T-shirt",
"url": "https://via.placeholder.com/150",
"type": "image",
"isFeatured": true
}
],
"variants": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "Color",
"options": [
{
"id": "550e8400-e29b-41d4-a716-446655440002",
"name": "Red"
},
{
"id": "550e8400-e29b-41d4-a716-446655440001",
"name": "Blue"
},
{
"id": "550e8400-e29b-41d4-a716-446655440003",
"name": "Green"
}
]
},
{
"id": "550e8400-e29b-41d4-a716-446655440111",
"name": "Size",
"options": [
{
"id": "550e8400-e29b-41d4-a716-446655440112",
"name": "Small"
},
{
"id": "550e8400-e29b-41d4-a716-446655440113",
"name": "Medium"
},
{
"id": "550e8400-e29b-41d4-a716-446655440114",
"name": "Large"
}
]
}
]
}
Important: For variant products, be sure to record the id values you assign to each variant option, as you will need them when creating prices.
After a successful request, the API response will include an _id field. This is your new product ID, which is required for the next step.
Creating a Price for the Product
Once the product is created, you can assign a price to it using the Create Price for a Product API endpoint.
Required Properties
The payload for creating a price requires the following properties:
- product: The ID of the product you created in the previous step.
- locationId: The sub-account ID.
- name: A name for the price.
- type: The billing type, which can be one_time or recurring.
- currency: The currency code for the price (e.g., USD).
- amount: The price amount.
- description: A description for the price.
- variantOptionIds: (For variant products only) An array containing the id values for the specific variant options this price applies to. For example, for a Red, Small t-shirt, you would provide the IDs for 'Red' and 'Small'. Omitting this for a variant product will cause display issues.
- trackInventory: A boolean to enable or disable inventory tracking for this price.
Example Payload for Price with Variants
For the t-shirt example, to set a price for a Red, Small variant, the payload would look like this. The variantOptionIds array contains the IDs for 'Red' and 'Small'.
{
"product": "<product_id>",
"locationId": "<sub_account_id>",
"name": "Red Small Price",
"type": "one_time",
"currency": "USD",
"amount": 1999,
"description": "Price for a Red, Small T-shirt",
"variantOptionIds": ["550e8400-e29b-41d4-a716-446655440002", "550e8400-e29b-41d4-a716-446655440112"],
"trackInventory": true
}
Conclusion
By following these steps—first creating the product and then creating a price for it—you can successfully build your product catalog using the CRM's public API. Remember to use the product ID from the first call in the second call to link the price correctly.