1

I have created a custom customer attribute(mobile_number) and set default value of customer create account.

I added mobile number to customer_attribute:

 $customerSetup->addAttribute(Customer::ENTITY, 'mobile_number', [
 'type' => 'varchar',
 'label' => 'Mobile Number',
 'input' => 'text',
 'required' => true,
 'visible' => true,
 'user_defined' => true,
 'sort_order' => 1000,
 'position' => 1000,
 'system' => 0,
 ]);

Now, its added, when created account manually its working fine and this mobile number details stored in customer_entity_varchar table.

I need to create a customer using rest api. I followed this link to send request via curl it throws an exeption that Mobile Number is required.

Curl Request:

curl -X POST "http://www.magento_server.net/index.php/rest/V1/customers" -H "Content-Type:application/json" -H "Authorization: Bearer xhfyo8cfvknpyd5dwuupe34uosh6tuhj" -d '{
 "customer": {
 "email": "[email protected]",
 "firstname": "First",
 "lastname": "Last",
 "storeId": 1,
 "websiteId": 1
 },
 "password": "Abc@123456",
 "mobile_number": "123-123-1234"
 }' | json_pp

Error:

{
 "trace" : "#0 /var/www/html/vendor/magento/module-customer/Model/ResourceModel/Customer.php(143): Magento\\Customer\\Model\\ResourceModel\\Customer->_validate(Object(Magento\\Customer\\Model\\Customer))\n#1 /var/www/html/vendor/magento/module-eav/Model/Entity/VersionControl/AbstractEntity.php(90): Magento\\Customer\\Model\\ResourceModel\\Customer->_beforeSave(Object(Magento\\Customer\\Model\\Customer))\n#2 /var/www/html/vendor/magento/framework/Model/AbstractModel.php(615): Magento\\Eav\\Model\\Entity\\VersionControl\\AbstractEntity->save(Object(Magento\\Customer\\Model\\Customer))\n#3 /var/www/html/vendor/magento/module-customer/Model/ResourceModel/CustomerRepository.php(195): Magento\\Framework\\Model\\AbstractModel->save()\n#4 [internal function]: Magento\\Customer\\Model\\ResourceModel\\CustomerRepository->save(Object(Magento\\Customer\\Model\\Data\\Customer), 'd9f8c7b5aed6d1f...')\n#5 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(144): call_user_func_array(Array, Array)\n#6 /var/www/html/var/generation/Magento/Customer/Model/ResourceModel/CustomerRepository/Interceptor.php(27): Magento\\Customer\\Model\\ResourceModel\\CustomerRepository\\Interceptor->___callPlugins('save', Array, Array)\n#7 /var/www/html/vendor/magento/module-customer/Model/AccountManagement.php(527): Magento\\Customer\\Model\\ResourceModel\\CustomerRepository\\Interceptor->save(Object(Magento\\Customer\\Model\\Data\\Customer), 'd9f8c7b5aed6d1f...')\n#8 /var/www/html/vendor/magento/module-customer/Model/AccountManagement.php(484): Magento\\Customer\\Model\\AccountManagement->createAccountWithPasswordHash(Object(Magento\\Customer\\Model\\Data\\Customer), 'd9f8c7b5aed6d1f...', '')\n#9 [internal function]: Magento\\Customer\\Model\\AccountManagement->createAccount(Object(Magento\\Customer\\Model\\Data\\Customer), 'Abc@123456', '')\n#10 /var/www/html/vendor/magento/module-webapi/Controller/Rest.php(265): call_user_func_array(Array, Array)\n#11 /var/www/html/vendor/magento/module-webapi/Controller/Rest.php(160): Magento\\Webapi\\Controller\\Rest->processApiRequest()\n#12 /var/www/html/var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(24): Magento\\Webapi\\Controller\\Rest->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#13 /var/www/html/vendor/magento/framework/App/Http.php(115): Magento\\Webapi\\Controller\\Rest\\Interceptor->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#14 /var/www/html/vendor/magento/framework/App/Bootstrap.php(258): Magento\\Framework\\App\\Http->launch()\n#15 /var/www/html/index.php(39): Magento\\Framework\\App\\Bootstrap->run(Object(Magento\\Framework\\App\\Http))\n#16 {main}",
 "message" : "\"Mobile Number\" is a required value."
}

Suggest me How to add our custom customer attribute field to rest api curl request and what miss in this query.

asked Apr 6, 2017 at 7:39

1 Answer 1

11

The custom attribute mobile_number should be inside custom customer attribute data:

{
 "customer": {
 "email": "[email protected]",
 "firstname": "First",
 "lastname": "Last",
 "storeId": 1,
 "websiteId": 1,
 "custom_attributes": [
 {
 "attribute_code": "mobile_number",
 "value": "23456798"
 }
 ]
 },
 "password": "Abc@123456"
}
answered Apr 6, 2017 at 7:57
4
  • My products API returns products, if i try with customer i am getting error, my url : 192.168.1.65/anusthana/api/rest/customers error : snag.gy/0jbhTr.jpg can u help me @khoa Commented Oct 23, 2018 at 10:57
  • @zus I didn't access directly by using Browser. I used curl. Commented Oct 23, 2018 at 11:46
  • @KhoaTruongDinh can you pls explain in brief? I am new in API. Commented Oct 23, 2018 at 12:17
  • @KhoaTruongDinh Here is my token : snag.gy/9BqesT.jpg and here is my key : snag.gy/HvzrAs.jpg then i what i need to proceed? Commented Oct 24, 2018 at 4:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.