• Version: 1.2.0

Modifiers

Through modifiers, you can add additional fields to your products. These fields allow you to create variations of your existing products. For example, if you are selling T-shirts, you can add modifiers for the size and the color. Once you add variations - the possible values for each modifier - you can sell each variant product individually.

Modifiers and variants use endpoints that extend off of the products/{product ID} endpoint:

  • https://api.molt.in/v1/products/{product ID}/modifiers to manage modifiers for a specific product.
  • https://api.molt.in/v1/products/{product ID}/modifiers/{modifier ID}/variations to manage variations for a specific modifier.

This topic will cover the following processes:

Add Fields to a Single Product

The modifers endpoint extends from the product/{product ID} endpoint we used to update a product above. Each modifier you create will add a new field to the selected product.

curl -X POST https://api.molt.in/v1/products/1019656230785778497/modifiers \
	-H "Authorization: Bearer XXXX" \
	-d "title=color" \
	-d "type=variant"

The number above is the ID of the product that you want to modify. The type data field is required and it must be set to “variant”. Optionally, you can pass the instructions data field to indicate what the user needs to do to select a variant. For example, “Select a color.”

A successful call call returns a 201 Created HTML status code and the following data:

{
	"status":true,
	"result":
	{
		"id":"1021106301108749095",
		"order":null,
		"created_at":"2015-07-03 17:42:25",
		"updated_at":"2015-07-03 17:42:25",
		"type":
		{
			"value":"Variant",
			"data":
			{
				"key":"variant",
				"value":"Variant"
			}
		},
		"title":"color",
		"instructions":"",
		"product":1019656230785778497,
		"images":[]
	}
}

In order to use this modifier, you must add the possible values as variants.

Add Variations to a Single Product

The endpoint you use to add variants extends off of the endpoints that we have already used: https://api.molt.in/v1/products/{product ID}/modifiers/{modifier ID}/variations.

curl -X POST https://api.molt.in/v1/products/1019656230785778497/modifiers/1021106301108749095/variations \
	-H "Authorization: Bearer XXXX" \
	-d "title=red"

This returns a 201 Created status code and the following data:

{
	"status":true,
	"result":
	{
		"id":"1021115054084326188",
		"order":null,
		"created_at":"2015-07-03 17:59:49",
		"updated_at":"2015-07-03 17:59:49",
		"title":"red",
		"mod_price":"+0.00",
		"modifier":1021106301108749095,
		"product":0
	}
}

While title is the only required field for this call, you can include the mod_price data field to increase of decrease the price of this variation by a set amount.

Using Multiple Modifiers and Variations

If you have products with multiple variation types - for example, T-shirts that can come in different sizes and colors - you can create two separate modifiers, each with their own sets of variations. This will create a sub-product for each combination of variables. In our T-shirt example, if we create three sizes (small, medium, and large) and three colors (red, blue, and black), we will have created nine different sub-products. By setting the mod_price field on a variation, you can have every one of these nine T-shirts sold at a different price. In our case, we’re going to modify the coffeemaker product from the (products)[#products] example, our sizes will in cups of coffee produced.

Below are the cURL statements that will create two new color variations with different prices, a size modifier, and three size variations.

Add color variations:

curl -X POST https://api.molt.in/v1/products/1019656230785778497/modifiers/1021106301108749095/variations \
	-H "Authorization: Bearer XXXX" \
	-d "title=blue" \
	-d "mod_price=+1.50"

curl -X POST https://api.molt.in/v1/products/1019656230785778497/modifiers/1021106301108749095/variations \
	-H "Authorization: Bearer XXXX" \
	-d "title=black" \
	-d "mod_price=-1.00"

Add the size variation:

curl -X POST https://api.molt.in/v1/products/1019656230785778497/modifiers \
	-H "Authorization: Bearer XXXX" \
	-d "title=size" \
	-d "type=variant"

Finally, add the three sizes:

curl -X POST https://api.molt.in/v1/products/1019656230785778497/modifiers/1021106301108749095/variations \
	-H "Authorization: Bearer XXXX" \
	-d "title=6cup" \
	-d "mod_price=-15.00"

curl -X POST https://api.molt.in/v1/products/1019656230785778497/modifiers/1021106301108749095/variations \
	-H "Authorization: Bearer XXXX" \
	-d "title=8cup"

	curl -X POST https://api.molt.in/v1/products/1019656230785778497/modifiers/1021106301108749095/variations \
	-H "Authorization: Bearer XXXX" \
	-d "title=12cup" \
	-d "mod_price=+2.00"

Here’s what the new product looks like:

{
	"status":true,
	"result":
	{
		"id":"1019656230785778497",
		"order":null,
		"created_at":"2015-07-01 17:41:28",
		"updated_at":"2015-08-28 17:49:46",
		"sku":"1893015",
		"title":"Mr. Coffee - 12-Cup Coffeemaker - Black\/Red",
		"slug":"mr-coffee-12cup-blackred",
		"sale_price":0,
		"status":
		{
			"value":"Live",
			"data":
			{
				"key":"1",
				"value":"Live"
			}
		},
		"category":
		{
			"value":"Home Appliances",
			"data":
			{
				"1018996345081430307":
				{
					"id":"1018996345081430307",
					"order":null,
					"created_at":"2015-06-30 19:50:24",
					"updated_at":"2015-06-3019:50:24",
					"parent":null,"slug":"home-appliances",
					"status":
					{
						"value":"Live",
						"data":
						{
							"key":"1",
							"value":"Live"
						}
					},
					"title":"Home Appliances",
					"description":"Appliances for your home"
				}
			}
		},
		"stock_level":0,
		"stock_status":
		{
			"value":"Unlimited",
			"data":
			{
				"key":"0",
				"value":"Unlimited"
			}
		},
		"description":"Brew delicious coffee with this Mr. Coffee FTX49 12-cup coffeemaker that features a fresh brew timer, so you can have a fresh cup in the morning. The 2-hour auto shutoff helps ensure safe operation.",
		"requires_shipping":
		{
			"value":"Yes",
			"data":
			{
				"key":"1",
				"value":"Yes"
			}
		},
		"weight":0,
		"height":0,
		"width":0,
		"depth":0,
		"catalog_only":
		{
			"value":"No",
			"data":
			{
				"key":"0",
				"value":"No"
			}
		},
		"tax_band":
		{
			"value":"Default",
			"data":
			{
				"id":"1018614836851901054",
				"title":"Default",
				"description":null,
				"rate":20,
				"created_at":null,
				"updated_at":null
			}
		},
		"collection":
		{
			"value":"Randoms",
			"data":
			{
				"id":"1019731797556069242",
				"order":null,
				"created_at":"2015-07-01 20:11:36",
				"updated_at":"2015-07-01 20:11:36",
				"slug":"randoms",
				"status":
				{
					"value":"Live",
					"data":
					{
						"key":"1",
						"value":"Live"
					}
				},
				"title":"Randoms",
				"description":"Some random products for testing"
			}
		},
		"brand":null,
		"price":
		{
			"value":"\u00a359.99",
			"data":
			{
				"formatted":
				{
					"with_tax":"\u00a359.99",
					"without_tax":"\u00a349.99",
					"tax":"\u00a310.00"
				},
				"rounded":
				{
					"with_tax":59.99,
					"without_tax":49.99,
					"tax":10
				},
				"raw":
				{
					"with_tax":59.988,
					"without_tax":49.99,
					"tax":9.998
				}
			}
		},
		"is_variation":false,
		"modifiers":
		{
			"1045049396858716721":
			{
				"id":"1045049396858716721",
				"order":null,
				"created_at":"2015-08-05 18:33:33",
				"updated_at":"2015-08-051 8:33:33",
				"type":
				{
					"value":"Variant",
					"data":
					{
						"key":"variant",
						"value":"Variant"
					}
				},
				"title":"color",
				"instructions":"",
				"product":"1019656230785778497",
				"variations":
				{
					"1102277896715632756":
					{
						"title":"red",
						"product":"",
						"modifier":"1045049396858716721",
						"mod_price":"+0.00",
						"id":"1102277896715632756",
						"difference":"+\u00a30.00"
					},
					"1102278540113477750":
					{
						"title":"blue",
						"product":"",
						"modifier":"1045049396858716721",
						"mod_price":"+1.50",
						"id":"1102278540113477750",
						"difference":"+\u00a30.00"
					},
					"1102278971623473272":
					{
						"title":"black",
						"product":"",
						"modifier":"1045049396858716721",
						"mod_price":"-1.00",
						"id":"1102278971623473272",
						"difference":"-\u00a31.00"
					}
				}
			},
			"1102279392823869562":
			{
				"id":"1102279392823869562",
				"order":null,
				"created_at":"2015-10-23 17:39:23",
				"updated_at":"2015-10-23 17:39:23",
				"type":
				{
					"value":"Variant",
					"data":
					{
						"key":"variant",
						"value":"Variant"
					}
				},
				"title":"size",
				"instructions":"",
				"product":"1019656230785778497",
				"variations":
				{
					"1102279986837979262":
					{
						"title":"6cup",
						"product":"",
						"modifier":"1102279392823869562",
						"mod_price":"-15.00",
						"id":"1102279986837979262",
						"difference":"-\u00a315.00"
					},
					"1102280547599646850":
					{
						"title":"8cup",
						"product":"",
						"modifier":"1102279392823869562",
						"mod_price":"+0.00",
						"id":"1102280547599646850",
						"difference":"+\u00a30.00"
					},
					"1102282167079141510":
					{
						"title":"12cup",
						"product":"",
						"modifier":"1102279392823869562",
						"mod_price":"+2.00",
						"id":"1102282167079141510",
						"difference":"-\u00a3-2.00"
					}
				}
			}
		},
		"images":[]
	},
	"pagination":
	{
		"items":
		{
			"previous":false,
			"next":"1044408599557701937"
		}
	}
}

Retrieve All Possible Variation Combinations for a Product

Once you have a product with variations, each of those variations can be treated like a sub-product. In order to use those, you’ll need the ID numbers of those variant products. With the https://api.molt.in/v1/products/{id number]/variations endpoint, you can return an array of all of the variant sub-products that exist for that product.

curl -X GET https://api.molt.in/v1/products/1019656230785778497/variations /
	-H "Authorization: Bearer XXXX"

This will return the product information for all of the variants associated with this product. Note that the returned products will have the variant names appended to both the title and the slug, which will allow you configure a separate store webpage for each variant combination.

Delete Fields for a Single Product

To remove a field, you use the same endpoint format we used to create it, except we include the modifier ID number at the end and use the DELETE request method.

curl -X DELETE https://api.molt.in/v1/products/1019656230785778497/modifiers/1021106301108749095 \
	-H "Authorization: Bearer XXXX" \

On success, this returns 200 OK and the following information:

{
	"status":true,
	"message":"Modifier removed successfully"
}

Delete Variations for a Single Product

To remove a variation, you use the same endpoint format we used to create it, except we include the variation ID number at the end and use the DELETE request method.

curl -X DELETE https://api.molt.in/v1/products/1019656230785778497/modifiers/1021106301108749095/variations/1021115054084326188 \
	-H "Authorization: Bearer XXXX" \

On success, this returns 200 OK and the following information:

{
	"status":true,
	"message":"Variation removed successfully"
}