Create a virtual 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 virtual 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
Creating a virtual product in Adobe Commerce. For this demonstration, I’m going to be accessing my commerce application using a bearer token. The method that you choose is up to you. Typically we suggest OAuth or an admin user account, but for this one, I’m just leveraging the original access token. So for this, we’re going to go ahead and use Postman, and we’re going to use the API first. And so the API that we’re going to be using is rest default v1 products, and we’re doing a post method. Our body is going to look something like this. There’s only four required attributes to create a product, a virtual product in Adobe Commerce. One being the SKU, the second being the name, the attribute set ID, you would get this from the commerce application by logging in and looking around at your different attribute sets that you want to use. In this case, raw installation usually starts with ID number four. For the price, we can just create some sort of price. And then the type ID is the word virtual. When we hit send, we’ll get our response. There we go. And I’m just going to grab the SKU, and we are going to do another API to test to see if it worked. This is going to be using the get method. Once again, just using a simple access bearer token. And there we go. Now we know it works. So now we’re going to go ahead and go to the admin of Adobe Commerce. And we are going to refresh our product page, and we’ll see our virtual product was created there. So we’re just going to go ahead and do the same process here, but we’re going to create it from the admin. So we’re going to go to virtual product. Once again, we just got to give it a name. The attribute set for this particular use case is going to be the default attribute set because I don’t have any other setup. Okay, we’re just going to give it a more friendly SKU. Okay, just like that. And I’ll just copy that for later. And then the price, we’ll just give it $55 and that’s it. So let’s save. And now if we go back to the main product grid, we’ll see we have the postman created product and the admin created product. And we can toggle back to postman and we can try our admin created SKU this time. And there it is, everything works as expected.
Create a virtual 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=2cd97649bcf4ee5b45b23f8eb940e3a0; private_content_version=564dde2976849891583a9a649073f01e' \
--data '{
"product": {
"sku": "postman-rest-virtual-product-test",
"name": "POSTMAN virtual product test",
"attribute_set_id": 4,
"price": 44,
"type_id": "virtual"
}
}
'
Get a product using curl
curl --location '{{your.url.here}}/rest/default/V1/products/Admin-created-virtual-product' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: PHPSESSID=2cd97649bcf4ee5b45b23f8eb940e3a0; private_content_version=564dde2976849891583a9a649073f01e'
Additional resources
recommendation-more-help
3a5f7e19-f383-4af8-8983-d01154c1402f