Magento 2 REST API Customer Custom Attribute

旧时模样 提交于 2019-12-10 19:22:01

问题


The Magento 2 REST API Documentation explains a way to set custom_attributes on a customer when updating or creating it. http://devdocs.magento.com/swagger/index_20.html#/

Unfortunately I couldn't get this to work...

My POST and PUT JSON request data is :

{
    "customer": {
        "custom_attributes": [
            {
                "attribute_code": "firstname",
                "value": "TEST"
            }
        ],
        "email": "someone@exaxmple.com",
        "extension_attributes": [],
        "firstname": "Someone",
        "gender": null,
        "lastname": "Else",
        "middlename": null,
        "taxvat": null,
        "website_id": "1"
    }
}

The Customer is created but the Firstname is not "TEST". Is there anyone who had the same problem and fixed it? Please let me know how.


回答1:


My best guess is that, since Firstname is an existing Out-Of-The-Box attribute - the OOTB attribute name-value mapping assignment will take precedence.

Could you try again, with a unique custom attribute name (i.e. something that doesn't clash with OOTB attribute names)

You will need to DEFINE a custom-customer-attribute before you can use the M2 API to perform operations on that custom-customer-attribute.

This StackExchange thread - https://magento.stackexchange.com/questions/88245/magento2-create-a-customer-custom-attribute - has additional information on how to go about setting up a custom-customer-attribute.



来源:https://stackoverflow.com/questions/46254405/magento-2-rest-api-customer-custom-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!