Skip to content

How to upload a new attribute via API?

I want to create an attribute from my android app written in Kotlin. For the explanation I am going to use Postman. Following is the code I use to create an attribute:

Post method:

https://mydomain.com/rest/V1/products/attributes

Headers

Content-Type: application/json

Authorization: Bearer lbxzbishecybtju0a27...

Body

{
  "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": "0",
    "used_in_product_listing": "1",
    "is_visible": true,
    "scope": "global",
    "attribute_code": "att_with_options",
    "frontend_input": "select",
    "entity_type_id": "4",
    "is_required": false,
    "options": [
      {
        "label": "Option1"
      },
      {
        "label": "Option2"
      },
      {
        "label": "Option3"
      }
    ],
    "is_user_defined": true,
    "default_frontend_label": "Att Label",
    "frontend_labels": null,
    "backend_type": "int",
    "source_model": "Magento%5C%5CEav%5C%5CModel%5C%5CEntity%5C%5CAttribute%5C%5CSource%5C%5CTable",
    "default_value": "",
    "is_unique": "0"
  }
}

The response I am getting is the following:

{
    "message": "The consumer isn't authorized to access %resources.",
    "parameters": {
        "resources": "Magento_Catalog::attributes_attributes"
    }
}

I think I have tried everything for example:

  • Web API Security Allow Anonymous Guest Access is set to true Allow
  • OAuth Access Tokens to be used as standalone Bearer tokens is set to
  • yes Magento cache is flushed ofcourse I am using sysemt ->
  • integrations -> Access Token with resource access set to all

Any help it would be much appreciated!