Create Attribute set in Magento 2 using Api
-
30-01-2021 - |
Question
I am trying to create an attribute set and assign multiple attribute into it using rest api
in Magento2
.
Please help me in this regard.
La solution
Magento 2 already have an API point for creating an attribute set.
http://www.example.com/rest/V1/products/attribute-sets
You have to hit API point
and have to post below value
{
"attributeSet": {
"attribute_set_name": "TESTAMIT",
"sort_order": 10,
"entity_type_id": 4
},
"skeletonId": 4
}
Here ,here
- skeletonId is the attribute set id on which your new attribute set
TESTAMIT
build. Here 4 is Magento default attribute setDefault
Id - "entity_type_id": 4 ,Here 4 products entity type id. Most of the time, when you want to build a new build that time system asking which attributes structure will you want to follow.
Example at CURL
curl -X POST \
http://www.example.com/rest/V1/products/attribute-sets \
-H 'authorization: Bearer p0jc2h1jwpha6gmje34frq9dm7x9liv4' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: 33e5dccd-7776-e22b-1a24-b484473cbe86' \
-d '{
"attributeSet": {
"attribute_set_name": "TESTAMIT",
"sort_order": 10,
"entity_type_id": 4
},
"skeletonId": 4
}'
PHP CURL
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://www.example.com/rest/V1/products/attribute-sets",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\n \"attributeSet\": {\n \"attribute_set_name\": \"TESTAMIT\",\n \"sort_order\": 10,\n \"entity_type_id\": 4\n },\n \"skeletonId\": 4\n}",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer p0jc2h1jwpha6gmje34frq9dm7x9liv4",
"cache-control: no-cache",
"content-type: application/json",
"postman-token: 10353b40-630e-ab82-849b-d6a23d7a52b2"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange