Create a simple product
Last update: Tue Nov 21 2023 00:00:00 GMT+0000 (Coordinated Universal Time)
CREATED FOR:
- Beginner
- Developer
- User
Learn how to create a simple product using the REST API and the Adobe Commerce Admin.
Who is this video for?
- Website managers
- eCommerce merchandisers
- New Adobe Commerce developers who want to learn how to create products in Adobe Commerce using the REST API.
Video content
Transcript
How to create a simple product in Adobe Commerce. I’m going to show you two methods. One is the API, the other is using the admin. For the API, I just want to elaborate that I am going to be using a simple bearer token. Your method for choosing how to communicate with your commerce application is up to you. For this example, we’re going to be posting it to my local base URL. We’re going to be using the defined API for REST for creating a product using the post method. There is only four minimum required attributes to create a product. One would be the SKU, the second would be the name, the third would be the attribute set ID, and you would get this by going to the Magento admin and finding it. By default, it starts with the number four typically. The price and then the type ID of simple product, because that’s the demonstration for this product. Under do that, we will use Postman and we’ll send it. There’s our result and let’s just prove that it works. What we need to do the get is we need the SKU. I already have it pre-configured. Let’s go ahead and hit send. There we go. We know it works. Next, I’m going to show you how to do this in the admin. Once you’ve logged into the admin and you go to catalog and then products, you can choose add product up on the top right-hand corner. For this demonstration, this is a simple product, so we’re going to click simple product. Give it a name. Once again, SKU is required and a price, so we’ll just give it a price. This is the attribute set. This is showing you the label, but under the hood, this is ID number four. Let’s save. Now, we can grab the SKU and we can go back to catalog products and we’ll see our two products created here. If we just wanted to prove that our API was working as well, we would post it in here. There we go.
Create a product using curl
curl --location '{{your.url.here}}/rest/default/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: PHPSESSID=a42da0096288718c9556f77549c6305f; private_content_version=564dde2976849891583a9a649073f01e' \
--data '{
"product": {
"sku": "some-product-sku",
"name": "My curl created product test",
"attribute_set_id": 4,
"price": 222,
"type_id": "simple"
}
}
Get a product using curl
curl --location '{{your.url.here}}rest/default/V1/products/some-product-sku' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: private_content_version=3b797a6cc3c5c71f2193109fb9838b12'
Additional resources
recommendation-more-help
3a5f7e19-f383-4af8-8983-d01154c1402f