Skip to content

Create a configurable product [Web API Tutorial]

Tomash Khamlai edited this page Jun 19, 2018 · 53 revisions

Create an attribute set for configurations

Let keep the Default attribute set from changing and create one new attribute set where we can add anything we will need.

Endpoint
POST http://<host>/rest/all/V1/products/attribute-sets

HTTP headers
Content-Type application/json
Authorization: Bearer <admin_token>

Payload

{
  "attributeSet": {
    "attribute_set_name": "Configurable Hoodies and Sweatshirts",
    "entity_type_id": 4
  },
  "skeletonId": 4
}

Response
Full information about the attribute set that was created with assigned attribute_set_id equal to 9

Complete cURL request sample

curl -X POST "$endpoint/all/V1/categories" \
 -H "Content-Type: application/json" \
 -H "Authorization: Bearer $admin_token" \
 -d '{"attributeSet":{"attribute_set_name":"Configurable Hoodies and Sweatshirts","entity_type_id":4},"skeletonId":4}' | json_pp

Place an attribute to the correct group Endpoint
PUT /V1/products/attribute-sets/9/groups

{
  "group": {
    "attribute_group_id": "30",
    "attribute_group_name": "Product Details",
    "attribute_set_id": 9
  }
}

Assign attribute to an attribute set

Endpoint
POST /V1/products/attribute-sets/attributes

HTTP headers

Content-Type: application/json 
Authorization: Bearer <admin_token>

Payload

{
  "attributeSetId": 9,
  "attributeGroupId": 30,
  "attributeCode": "size",
  "sortOrder": 0
}

Response

Complete cURL request

Create an attribute

Endpoint
POST http://<host>/rest/all/V1/products/attributes

HTTP headers

Content-Type: application/json 
Authorization: Bearer <admin_token>

Payload

{
	"attribute": {
		"attribute_code": "size",
		"entity_type_id": "4",
                "default_frontend_label": "Size",
		"frontend_labels": [{
			"store_id": 1,
			"label": "Size"
		},{
			"store_id": 2,
			"label": "Size"
		}],
		"is_required": true,
		"default_value": "",
		"frontend_input": "select",
		"is_visible_on_front": true,
		"is_searchable": true,
		"is_visible_in_advanced_search": true,
		"is_filterable": true,
		"is_filterable_in_search": true,
		"options": [{
			"label": "S",
			"value": "S",
			"sort_order": 100,
			"is_default": true,
			"store_labels": [{
				"store_id": 2,
				"label": "Size S"
			}, {
				"store_id": 1,
				"label": "Size S"
			}]
		}, {
			"label": "M",
			"value": "M",
			"sort_order": 0,
			"is_default": false,
			"store_labels": [{
				"store_id": 2,
				"label": "Size M"
			}, {
				"store_id": 1,
				"label": "Size M"
			}]
		}, {
			"label": "L",
			"value": "L",
			"sort_order": 0,
			"is_default": false,
			"store_labels": [{
				"store_id": 2,
				"label": "Size L"
			}, {
				"store_id": 1,
				"label": "Size L"
			}]
		}, {
			"label": "XL",
			"value": "XL",
			"sort_order": 0,
			"is_default": false,
			"store_labels": [{
				"store_id": 2,
				"label": "Size XL"
			}, {
				"store_id": 1,
				"label": "Size XL"
			}]
		}, {
			"label": "XXL",
			"value": "XXL",
			"sort_order": 0,
			"is_default": false,
			"store_labels": [{
				"store_id": 2,
				"label": "Size XXL"
			}, {
				"store_id": 1,
				"label": "Size XXL"
			}]
		}]
	}
}

Complete cUrl request

curl -X POST "$endpoint/all/V1/products/attributes " \
 -H "Content-Type: application/json" \
 -H "Authorization: Bearer $admin_token" \
 -d '{"attribute":{"attribute_code":"size","entity_type_id":"4","default_frontend_label":"Size","frontend_labels":[{"store_id":1,"label":"Size"},{"store_id":2,"label":"Size"}],"is_required":true,"default_value":"","frontend_input":"select","is_visible_on_front":true,"is_searchable":true,"is_visible_in_advanced_search":true,"is_filterable":true,"is_filterable_in_search":true,"options":[{"label":"S","value":"S","sort_order":100,"is_default":true,"store_labels":[{"store_id":2,"label":"Size S"},{"store_id":1,"label":"Size S"}]},{"label":"M","value":"M","sort_order":0,"is_default":false,"store_labels":[{"store_id":2,"label":"Size M"},{"store_id":1,"label":"Size M"}]},{"label":"L","value":"L","sort_order":0,"is_default":false,"store_labels":[{"store_id":2,"label":"Size L"},{"store_id":1,"label":"Size L"}]},{"label":"XL","value":"XL","sort_order":0,"is_default":false,"store_labels":[{"store_id":2,"label":"Size XL"},{"store_id":1,"label":"Size XL"}]},{"label":"XXL","value":"XXL","sort_order":0,"is_default":false,"store_labels":[{"store_id":2,"label":"Size XXL"},{"store_id":1,"label":"Size XXL"}]}]}}'

Step 2. Create a category

Endpoint
POST http:///rest/all/V1/categories"

HTTP headers
Content-Type application/json
Authorization: Bearer <admin_token>

Payload

{
	"category": {
		"parent_id": 2,
		"name": "Hoodies & Sweatshirts",
		"is_active": true,
		"level": 2,
		"include_in_menu": true,
		"custom_attributes": [{
			"attribute_code": "is_anchor",
			"value": "1"
		}, {
			"attribute_code": "url_key",
			"value": "hoodies-sweatshirts"
		}, {
			"attribute_code": "url_path",
			"value": "hoodies-sweatshirts"
		}]
	}
}

Response
Full information about the category that was created

Complete cURL request sample

curl -X POST "$endpoint/all/V1/categories" \
 -H "Content-Type: application/json" \
 -H "Authorization: Bearer $admin_token" \
 -d '{"category":{"parent_id":2,"name":"Hoodies & Sweatshirts","is_active":true,"level":2,"include_in_menu":true,"custom_attributes":[{"attribute_code":"is_anchor","value":"1"},{"attribute_code":"url_key","value":"hoodies-sweatshirts"},{"attribute_code":"url_path","value":"hoodies-sweatshirts"}]}}' | json_pp

Step 3. Create the product

Endpoint
POST http://<host>/rest/test/V1/products

HTTP headers

Content-Type application/json  
Authorization: Bearer <admin_token>

Payload

Response

Complete cURL request sample

MSI Documentation:

  1. Technical Vision. Catalog Inventory
  2. Installation Guide
  3. List of Inventory APIs and their legacy analogs
  4. MSI Roadmap
  5. Known Issues in Order Lifecycle
  6. MSI User Guide
  7. DevDocs Documentation
  8. User Stories
  9. User Scenarios:
  10. Technical Designs:
  11. Admin UI
  12. MFTF Extension Tests
  13. Weekly MSI Demos
  14. Tutorials
Clone this wiki locally