cancel
Showing results for 
Search instead for 
Did you mean: 

REST API customer Registration Custom Attribute as Paramter

SOLVED

REST API customer Registration Custom Attribute as Paramter

Hi,

 

I've added a custom attribute 'residency' to customers which I'll use on registration.

 

I've been using this parameters:

{
"customer": {
"email": "customer@test.com",
"firstname": "abc",
"lastname": "def",
"dob": "1994-01-21",
"gender": 1,
"store_id":1,

"residency": "testResidency"
},
"password": "Password1234"

}

 

Methods that i've tried:

  • override the CustomerInterface (returns an error that it cant be overriden)
  • used extension_attributes.xml (all my rest api calls returns "Consumer is not authorized to access %resources" after i run setup:di:compile)

note:
when I register thru my customer registration page. the attribute is being populated.

its just that when I call the rest API that Im having issues.

 

Any help would be greatly appreciated. Thanks!



 

REST api: V1/customers

1 ACCEPTED SOLUTION

Accepted Solutions

Re: REST API customer Registration Custom Attribute as Paramter

I've got it working.

 

for those that might run into the same problem.

all I did was make a extension_attributes.xml and change the way I pass the custom attributes on my parameters.

 

Custom attribute: residency

 

extension_attributes.xml:

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="Magento\Customer\Api\Data\CustomerInterface">
        <attribute code="residency" type="string"/>
    </extension_attributes>
</config>

parameters:

{
	"customer": {
		"email": "test@customer.com",
		"firstname": "abc",
		"lastname": "def",
		"dob": "1994-01-21",
		"gender": 1,
		"store_id":1,
		"extension_attributes": {
              "residency":"sample residency"
			}
		},
	"password": "Password1234"
}

 

View solution in original post

2 REPLIES 2

Re: REST API customer Registration Custom Attribute as Paramter

I've got it working.

 

for those that might run into the same problem.

all I did was make a extension_attributes.xml and change the way I pass the custom attributes on my parameters.

 

Custom attribute: residency

 

extension_attributes.xml:

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="Magento\Customer\Api\Data\CustomerInterface">
        <attribute code="residency" type="string"/>
    </extension_attributes>
</config>

parameters:

{
	"customer": {
		"email": "test@customer.com",
		"firstname": "abc",
		"lastname": "def",
		"dob": "1994-01-21",
		"gender": 1,
		"store_id":1,
		"extension_attributes": {
              "residency":"sample residency"
			}
		},
	"password": "Password1234"
}

 

Re: REST API customer Registration Custom Attribute as Paramter

have you created plugin for the same??