-
Notifications
You must be signed in to change notification settings - Fork 248
Create a downloadable product [Web API Tutorial]
Let us keep the Default attribute set from changing and create the new one.
Endpoint
POST http://<host>/rest/all/V1/eav/attribute-sets
HTTP headers
Content-Type: application/json
Authorization: Bearer <admin_token>
Payload
{
"entityTypeCode": "catalog_product",
"attributeSet": {
"attribute_set_name": "Downloadable",
"entity_type_id": 4
},
"skeletonId": 4
}
Response
Full information about the attribute set that was created with assigned attribute_set_id
Complete cURL request sample
curl -X POST "$endpoint/all/V1/eav/attribute-sets" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"entityTypeCode":"catalog_product","attributeSet":{"attribute_set_name":"Downloadable","entity_type_id":4},"skeletonId":4}' | json_pp
Endpoint
POST http://<host>/rest/all/V1/products/attributes
HTTP headers
Content-Type: application/json
Authorization: Bearer <admin_token>
Payload
{
"attribute": {
"attribute_code": "format",
"entity_type_id": "4",
"default_frontend_label": "Format",
"is_required": false,
"default_value": "",
"frontend_input": "select",
"is_visible_on_front": "1",
"is_searchable": "0",
"is_visible_in_advanced_search": "0",
"is_filterable": true,
"is_filterable_in_search": false,
"options": [
{
"label": "Download",
"value": "option-download"
},
{
"label": "DVD",
"value": "option-dvd"
}
]
}
}
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":"format","entity_type_id":"4","default_frontend_label":"Format","is_required":false,"default_value":"","frontend_input":"select","is_visible_on_front":"1","is_searchable":"0","is_visible_in_advanced_search":"0","is_filterable":true,"is_filterable_in_search":false,"options":[{"label":"Download","value":"option-download"},{"label":"DVD","value":"option-dvd"}]}}' | json_pp
Endpoint
POST http://<host>/rest/all/V1/products/attributes
HTTP headers
Content-Type: application/json
Authorization: Bearer <admin_token>
Payload
{
"attribute": {
"attribute_code": "activity",
"default_frontend_label": "Activity",
"default_value": "",
"entity_type_id": "4",
"frontend_input": "multiselect",
"is_filterable": true,
"is_filterable_in_grid": false,
"is_filterable_in_search": false,
"is_required": false,
"is_searchable": "0",
"is_visible_in_advanced_search": "0",
"is_visible_on_front": "1",
"options": [
{
"label": "Running",
"value": "Running"
},
{
"label": "Warmup",
"value": "Warmup"
},
{
"label": "Yoga",
"value": "Yoga"
},
{
"label": "Gym",
"value": "Gym"
},
{
"label": "Cycling",
"value": "Cycling"
},
{
"label": "Athletic",
"value": "Athletic"
},
{
"label": "Sports",
"value": "Sports"
},
{
"label": "Hiking",
"value": "Hiking"
}
],
"scope": "global",
"used_in_product_listing": "0"
}
}
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":"activity","default_frontend_label":"Activity","default_value":"","entity_type_id":"4","frontend_input":"multiselect","is_filterable":true,"is_filterable_in_grid":false,"is_filterable_in_search":false,"is_required":false,"is_searchable":"0","is_visible_in_advanced_search":"0","is_visible_on_front":"1","options":[{"label":"Running","value":"Running"},{"label":"Warmup","value":"Warmup"},{"label":"Yoga","value":"Yoga"},{"label":"Gym","value":"Gym"},{"label":"Cycling","value":"Cycling"},{"label":"Athletic","value":"Athletic"},{"label":"Sports","value":"Sports"},{"label":"Hiking","value":"Hiking"}],"scope":"global","used_in_product_listing":"0"}}' | json_pp
The attributeSetId
, attributeGroupId
, attributeCode
, sortOrder
attributes are required. The value for attributeSetId
you have already obtained in Create an attribute set for configurations step. What about other attributes? Read about Data preparation before assigning attribute to an attribute set
Endpoint
POST /V1/products/attribute-sets/attributes
HTTP headers
Content-Type: application/json
Authorization: Bearer <admin_token>
Payload
{
"attributeSetId": 10,
"attributeGroupId": 40,
"attributeCode": "format",
"sortOrder": 30
}
Response
Complete cURL request
curl -X POST "$endpoint/all/V1/products/attribute-sets/attributes" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"attributeSetId":10,"attributeGroupId":40,"attributeCode":"format","sortOrder":30}' | json_pp -json_opt allow_nonref
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":"activity","default_frontend_label":"Activity","default_value":"","entity_type_id":"4","frontend_input":"multiselect","is_filterable":true,"is_filterable_in_grid":false,"is_filterable_in_search":false,"is_required":false,"is_searchable":"0","is_visible_in_advanced_search":"0","is_visible_on_front":"1","options":[{"label":"Running","value":"Running"},{"label":"Warmup","value":"Warmup"},{"label":"Yoga","value":"Yoga"},{"label":"Gym","value":"Gym"},{"label":"Cycling","value":"Cycling"},{"label":"Athletic","value":"Athletic"},{"label":"Sports","value":"Sports"},{"label":"Hiking","value":"Hiking"}],"scope":"global","used_in_product_listing":"0"}}' | json_pp
The attributeSetId
, attributeGroupId
, attributeCode
, sortOrder
attributes are required. The value for attributeSetId
you have already obtained in Create an attribute set for configurations step. What about other attributes? Read about Data preparation before assigning attribute to an attribute set
Endpoint
POST /V1/products/attribute-sets/attributes
HTTP headers
Content-Type: application/json
Authorization: Bearer <admin_token>
Payload
{
"attributeSetId": 10,
"attributeGroupId": 40,
"attributeCode": "activity",
"sortOrder": 40
}
Response
Complete cURL request
curl -X POST "$endpoint/all/V1/products/attribute-sets/attributes" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"attributeSetId":10,"attributeGroupId":40,"attributeCode":"activity","sortOrder":40}' | json_pp -json_opt allow_nonref
Endpoint
POST http://<host>/rest/all/V1/categories"
HTTP headers
Content-Type application/json
Authorization: Bearer <admin_token>
Payload
{
"category": {
"parent_id": 2,
"name": "Training",
"is_active": true,
"level": 2,
"include_in_menu": true,
"custom_attributes": [{
"attribute_code": "is_anchor",
"value": "1"
}, {
"attribute_code": "url_key",
"value": "training"
}, {
"attribute_code": "url_path",
"value": "train"
}]
}
}
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":"Training","is_active":true,"level":2,"include_in_menu":true,"custom_attributes":[{"attribute_code":"is_anchor","value":"1"},{"attribute_code":"url_key","value":"training"},{"attribute_code":"url_path","value":"training"}]}}' | json_pp | grep -i '"id"'
Create category Video Download
Payload
{
"category": {
"parent_id": 6,
"name": "Video Download",
"is_active": true,
"level": 3,
"include_in_menu": true,
"custom_attributes": [{
"attribute_code": "is_anchor",
"value": "1"
}, {
"attribute_code": "url_key",
"value": "video-download"
}, {
"attribute_code": "url_path",
"value": "video-download"
}]
}
}
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":6,"name":"Video Download","is_active":true,"level":3,"include_in_menu":true,"custom_attributes":[{"attribute_code":"is_anchor","value":"1"},{"attribute_code":"url_key","value":"video-download"},{"attribute_code":"url_path","value":"video-download"}]}}' | json_pp | grep -i '"id"'
Endpoint
POST http://<host>/rest/test/V1/products
HTTP headers
Content-Type application/json
Authorization: Bearer <admin_token>
Payload
Response
Complete cURL request sample
wget https://magento.com/sites/all/themes/mag_redesign/images/magento-adobe-logo.svg
base64_encode() { php -r 'print(base64_encode(file_get_contents($argv[1])));' $1; }
file_data=$(base64_encode $PWD/magento-adobe-logo.svg)
file_data=${file_data////\\/}
echo $file_data
curl -X POST "$endpoint/test/V1/products" -H "Content-Type: application/json" -H "Authorization: Bearer $admin_token" -d '{"product":{"sku":"sku-test-product-downloadable3","name":"sku-test-product-downloadable3","type_id":"downloadable","price":10,"attribute_set_id":10,"extension_attributes":{"category_links":[{"position":0,"category_id":"7"}],"downloadable_product_links":[{"title":"link1","sort_order":10,"is_shareable":1,"price":2,"number_of_downloads":0,"link_type":"file","link_file_content":{"name":"link1_content.svg","file_data":"'"$file_data"'"},"sample_type":"file","sample_file_content":{"name":"link1_sample.svg","file_data":"'"$file_data"'"}},{"title":"link2","sort_order":20,"is_shareable":0,"price":3,"number_of_downloads":100,"link_type":"url","link_url":"http://www.example.com/link2.jpg","sample_type":"url","sample_url":"http://www.example.com/link2.jpg"}],"downloadable_product_samples":[{"title":"sample1","sort_order":10,"sample_type":"url","sample_url":"http://www.example.com/sample1.jpg"},{"title":"sample2","sort_order":20,"sample_type":"file","sample_file_content":{"name":"sample2.svg","file_data":"'"$file_data"'"}}]},"custom_attributes": [{"attribute_code":"format","value":"9"},{"attribute_code":"activity","value":"14,16,17"}]}}'
📖 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