SourCherry Help Centre
HomeE-commerce storeE-Commerce Store

Create a Product with Price using Public API

TABLE OF CONTENTS

  1. Introduction
  2. Products
    1. Types of Products
      1. Products with Price
      2. Products with Variants
  3. Create Product using Public API
    1. Authorization
    2. Creation of Product
      1. Create Product
      2. Example Payload for Product with Price:
      3. Example Payload for Product with Variants:
      4. Create Price for a Product
      5. Example Payload for Price for Product With Variants
    3. Add Image to a variant through Public API
      1. Example Payload for Product Media Update with PriceIds
  4. Conclusion


Introduction

This article mainly aims to guide the users on how to create a product using the public API provided by SourCherry. It also delves down for the cases and several types which the users can take the advantage of while creating a product



Products

Products are the one of the main entities in SourCherry using which, users can sell the products that they want to sell through many forms of selling channels, using E-commerce Stores, Invoices, Estimates, and more


Types of Products

In SourCherry, products are majorly of two type products: 


Products with Price

These types of products are simple products which don't have any variants to them. Any product which doesn't require variants (or) has only 1 variant classification can be created in this format. Best example would be Poster with possible sizes


Products with Variants

This type of products are the products which have multiple variations for a single product. Best example would be a T-shirt where there might be multiple colors and sizes



Create Product using Public API

Authorization

In order to perform CRUD (Create, Read, Update and Delete) entities related to SourCherry using Public API, we need access token. The authorization process is explained in the below link:


https://marketplace.SourCherry.com/docs/Authorization/authorization_doc


Creation of Product

For creating a product we are going to utilize the following Public APIs

It is advised to follow the order of the content in order to create a Product


Create Product

First we need to create a product using the Create a Product API . Let us see the basic properties required for Creation of Product

Example Payload for Product with Price:

{
"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 Payload for Product with 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"
}
]
}
]
}
Note: For Variant Product, keep in track of the option Ids as they will be playing an important role while creating price

Upon creating a product, we will get a response which will have the property _id which is the created productId. That will be used to create price for a product


Create Price for a Product

We will be using the Create Price for a Product API to create a price for product. Here are the basic properties required for creating a price for a product

  ["550e8400-e29b-41d4-a716-446655440002","550e8400-e29b-41d4-a716-446655440112"]

Example Payload for Simple Price (Without Variants):

    {
"product": "66b6021be68f7a98102ba272",
"locationId": "<sub_account_id>",
"name": "256 GB",
"type": "one_time",
"currency": "USD",
"amount": 100,
"description": "256 GB of storage",
"sku": "PS-256GB",
"isDigitalProduct": false,
"shippingOptions": {
"weight": {
"value": 100,
"unit": "g"
},
"dimensions": {
"length": 10,
"width": 10,
"height": 10,
"unit": "cm"
}
}
}

Example Payload for Price for Product With Variants

{
"product": "66b6021be68f7a98102ba272",
"locationId": "<sub_account_id>",
"name": "Red / Small",
"type": "one_time",
"currency": "USD",
"amount": 100,
"description": "Red / Small",
"sku": "PS-RED-SMALL",
"isDigitalProduct": false,
"variantOptionIds": ["550e8400-e29b-41d4-a716-446655440002","550e8400-e29b-41d4-a716-446655440112"],
"shippingOptions": {
"weight": {
"value": 100,
"unit": "g"
},
"dimensions": {
"length": 10,
"width": 10,
"height": 10,
"unit": "cm"
}
}
}
Note: Variant Option Ids are required for correct rendering of the product variations


Add Image to a variant through Public API

This feature is available only for variant type of products and not price type of products. After creating Price for a product, in the response we will get the Internal Id of the price. Using that we will now update the images for specific variants. Using the received priceIds, we will update the product again with the following payload. 


Example Payload for Product Media Update with PriceIds

In the product payload, there will be an array for medias, each and every media array is provided with a property called "priceIds" which in turn is an array, By assigning the respective priceIds, the media will get mapped to variants automatically. 
{
  "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",
      "priceIds": ["<created_price_Id>"],
      "isFeatured": true
    }
  ],
  "variants": [
   {...existing variants data}
  ]
}
As of now, we support only one image mapped to one priceId, mapping multiple priceIds to a single image will cause problems in rending the products

Conclusion

Using the above APIs we were able to create a basic ONE TIME Physical product with simple price and also with variants. The flexibility doesn't stop here, as SourCherry supports recurring Products as well, you can refer to the Price API documentation in detail and make use of the properties specifically provided for recurring products