2

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.

3

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 set Default 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;
}
  • can you explain a bit more on skeletonId,entity_type_id – Magento Learner Oct 4 '18 at 10:52
  • @Amit, is any api for creating attribute? – jafar pinjar Jan 7 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.