0

I have created the custom attribute through rest API and it is also reflected in magento admin, after which when I tried to update the product with the attribute code.it won't worked.

Below is my JSON for creating attribute code

 $data = [
                           "attribute" => [
                                 "is_wysiwyg_enabled" => false,
                                 "is_html_allowed_on_front" => false,
                                 "used_for_sort_by" => false,
                                 "is_filterable"=> true,
                                 "is_filterable_in_search"=> true,
                                 "is_used_in_grid"=> true,
                                 "is_visible_in_grid"=> false,
                                 "is_filterable_in_grid"=> true,
                                 "position"=> 0,
                                 "apply_to"=> [],
                                 "is_searchable"=> "1",
                                 "is_visible_in_advanced_search"=> "1",
                                 "is_comparable"=> "1",
                                 "is_used_for_promo_rules"=> "0",
                                 "is_visible_on_front"=> "1",
                                 "used_in_product_listing"=> "1",
                                 "is_visible"=> true,
                                 "scope"=> "global",
                                 "frontend_input"=> "text",
                                 "entity_type_id"=> "4",
                                 "is_required"=> false,
                                 "is_user_defined"=> true,
                                 "default_frontend_label"=> $attribute,
                                 "frontend_labels"=> $attribute,
                                 "backend_type"=> "varchar",
                                 "default_value"=> "",
                                 "is_unique"=> "0",
                                //  'attribute_set' => 'Default', // Specify the attribute set code
                                //  'attribute_group' => 'General',    
                             ]
                         ];

This is for product updating for custom attribute

$data = [
                      "product" => [
                        "sku"=> $productsku,
                       // "attribute_set_id"=> 4,
                        //"attribute_set_id" => $mage_attr_set_id,
                       // "entity_type_id" => $entity_type_id,
                        "visibility" => 2,
                        // "custom_attributes" => $subArray
                        "custom_attributes" => [
                            [
                            "attribute_code" => "selling_unit_of_measure",
                            "value" => "each"
                            
                            ] 
                      ]
                      ]
                    ];

1 Answer 1

0

To update product using Postman and REST API

URL: /rest/V1/products/{SKU}
Method : PUT

the JSON data to pass or you can take reference on product JSON string from https://developer.adobe.com/commerce/webapi/rest/tutorials/configurable-product/create-simple-products/

    {
  "product": {
    "custom_attributes": [
      {
        "attribute_code": "color",
        "value": "49"
      }
    ]
  }
}

You can have the same added to your file or script just use the PUT method with the correct JSON data. Hope it helps

2
  • First I created a custom attibute and i tried to update product with that attribute code but when i tried to update that doesnt work. For instance selling_unit_of_measure this attribute created from rest api and pass this value to product.I hope you Understand. Jan 12 at 11:33
  • have you assigned it to the correct attribute set... can you confirm if you are able to update the attribute value therough admin pages Jan 12 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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