-
Notifications
You must be signed in to change notification settings - Fork 248
Create a simple product [Web API Tutorial]
Ievgen Shakhsuvarov edited this page Jul 16, 2019
·
7 revisions
At this point we are going to create 2 categories: Sports Equipment and Backpacks
Endpoint
POST http://<host>/rest/all/V1/categories"
HTTP headers
Content-Type application/json
Authorization: Bearer <admin_token>
Payload
{
"category": {
"parent_id": 2,
"name": "Sports Equipment",
"is_active": true,
"level": 2,
"include_in_menu": true,
"custom_attributes": [{
"attribute_code": "is_anchor",
"value": "1"
}, {
"attribute_code": "url_key",
"value": "sports-equipment"
}, {
"attribute_code": "url_path",
"value": "sports-equipment"
}]
}
}
Repeat this with another payload:
Payload
{
"category": {
"parent_id": 3,
"name": "Backpacks",
"is_active": true,
"level": 3,
"include_in_menu": true,
"custom_attributes": [{
"attribute_code": "is_anchor",
"value": "1"
}, {
"attribute_code": "url_key",
"value": "backpacks"
}, {
"attribute_code": "url_path",
"value": "backpacks"
}]
}
}
Response
Full information about the category that was created
Complete cURL request sample
default_category_id=2 && curl -X POST "$endpoint/all/V1/categories" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"category":{"parent_id":"'"$default_category_id"'","name":"Sport Equipment","is_active":true,"include_in_menu":true,"custom_attributes":[{"attribute_code":"is_anchor","value":"1"},{"attribute_code":"url_key","value":"sports-equipment"},{"attribute_code":"url_path","value":"sports-equipment"}]}}' | json_pp
sports_equipment_category_id=3 && curl -X POST "$endpoint/all/V1/categories" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"category":{"parent_id":"'"$sports_equipment_category_id"'","name":"Backpacks","is_active":true,"include_in_menu":true,"custom_attributes":[{"attribute_code":"is_anchor","value":"1"},{"attribute_code":"url_key","value":"backpacks"},{"attribute_code":"url_path","value":"backpacks"}]}}' | json_pp
After this step the simple product with SKU
'Simple Running Backpack' will be added to the products inventory.
Endpoint
POST http://<host>/rest/test/V1/products
HTTP headers
Content-Type application/json
Authorization: Bearer <admin_token>
Payload
{
"product": {
"sku": "Simple Running Backpack",
"name": "Simple Running Backpack",
"attribute_set_id": 4,
"price": 70,
"status": 1,
"visibility": 4,
"type_id": "simple",
"weight": 0.8,
"extension_attributes": {
"website_ids": ["2"],
"category_links": [{
"position": 0,
"category_id": "3"
}],
"stock_item": {
"qty": 250,
"is_in_stock": true,
"is_qty_decimal": false
}
}
}
}
Response
Magento returns new entity.
Complete cURL request sample
backpacks_category_id="3"; simple_product_SKU="Simple Running Backpack"; test_website_id="2" && curl -X POST "$endpoint/test/V1/products" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"product":{"sku":"'"$simple_product_SKU"'","name":"'"$simple_product_SKU"'","attribute_set_id":4,"price":70,"status":1,"visibility":4,"type_id":"simple","weight":0.8,"extension_attributes":{"website_ids":["'"$test_website_id"'"],"category_links":[{"position":0,"category_id":"'"$backpacks_category_id"'"}],"stock_item":{"qty":250,"is_in_stock":true,"is_qty_decimal":false}}}}' | json_pp
📖 Table of Contents | Next Step |
Multi-Source Inventory developed by Magento 2 Community
- Technical Vision. Catalog Inventory
- Installation Guide
- List of Inventory APIs and their legacy analogs
- MSI Roadmap
- Known Issues in Order Lifecycle
- MSI User Guide
- 2.3 LIVE User Guide
- MSI Release Notes and Installation
- Overview
- Get Started with MSI
- MSI features and processes
- Global and Product Settings
- Configure Source Selection Algorithm
- Create Sources
- Create Stock
- Assign Inventory and Product Notifications
- Configure MSI backorders
- MSI Import and Export Product Data
- Mass Action Tool
- Shipment and Order Management
- CLI reference
- Reports and MSI
- MSI FAQs
- DevDocs Documentation
- Manage Inventory Management Modules (install/upgrade info)
- Inventory Management
- Reservations
- Inventory CLI reference
- Inventory API reference
- Inventory In-Store Pickup API reference
- Order Processing with Inventory Management
- Managing sources
- Managing stocks
- Link and unlink stocks and sources
- Manage source items
- Perform bulk actions
- Manage Low-Quantity Notifications
- Check salable quantities
- Manage source selection algorithms
- User Stories
- Support of Store Pickup for MSI
- Product list assignment per Source
- Source assignment per Product
- Stocks to Sales Channel Mapping
- Adapt Product Import/Export to support multi Sourcing
- Introduce SourceCode attribute for Source and SourceItem entities
- Assign Source Selector for Processing of Returns Credit Memo
- User Scenarios:
- Technical Designs:
- Module Structure in MSI
- When should an interface go into the Model directory and when should it go in the Api directory?
- Source and Stock Item configuration Design and DB structure
- Stock and Source Configuration design
- Open Technical Questions
- Inconsistent saving of Stock Data
- Source API
- Source WebAPI
- Sources to Sales Channels mapping
- Service Contracts MSI
- Salable Quantity Calculation and Mechanism of Reservations
- StockItem indexation
- Web API and How To cover them with Functional Testing
- Source Selection Algorithms
- Validation of Domain Entities
- PHP 7 Syntax usage for Magento contribution
- The first step towards pre generated IDs. And how this will improve your Integration tests
- The Concept of Default Source and Domain Driven Design
- Extension Point of Product Import/Export
- Source Selection Algorithm
- SourceItem Entity Extension
- Design Document for changing SerializerInterface
- Stock Management for Order Cancelation
- Admin UI
- MFTF Extension Tests
- Weekly MSI Demos
- Tutorials