0

I am using Magento 2 official B2B extension and I am trying to create customers via the REST API and assign it to a company on creation.

Sending a POST request to /rest/default/V1/customers with the below data I get back a response.

{
 "customer": {
 "email": "[email protected]",
 "firstname": "API",
 "lastname": "test",
 "website_id": 4,
 "extension_attributes": {
 "company_attributes": {
 "company_id": 1,
 "status": 0
 }
 },
 "customAttributes": [
 {
 "attributeCode": "amasty_store_id",
 "value": "323"
 },
 {
 "attributeCode": "company_id",
 "value": "1"
 }
 ]
 }
}

When the response comes back I can see the "status" takes effect but the company_id doesn't take effect. I tried passing it as a customAttribute above but it had no effect.

...
"extension_attributes": {
 "company_attributes": {
 "customer_id": 88,
 "company_id": 0,
 "status": 0
 },
 "is_subscribed": false
},
...

I did try with the editing customer api PUT /rest/default/V1/customers/88 and this worked to assign a customer to a company via the API using the extension_attributes method. But I haven't been able to find a way to 'create' a customer in a company via the API.

asked Mar 24 at 5:06
1

1 Answer 1

0

We can't directly assign to the company, Here is the ideas to apply customer for company.

PUT <host>/rest/default/V1/customers/10

Payload:

{
"customer": {
"id": 10,
"email": "[email protected]",
"firstname": "Test",
"lastname": "Dev",
"website_id": 1,
"extension_attributes": {
 "company_attributes": {
 "company_id": 2,
 "status": 0,
 "job_title": "Sales Rep",
 "telephone": "123-123-1122"
 }
 }
 }
}

Respons:

{
 "id": 10,
 "group_id": 1,
 "created_at": "2017年05月18日 16:47:44",
 "updated_at": "2017年05月18日 18:50:58",
 "created_in": "Default Store View",
 "email": "[email protected]",
 "firstname": "Test",
 "lastname": "Dev",
 "store_id": 1,
 "website_id": 1,
 "addresses": [],
 "disable_auto_group_change": 0,
 "extension_attributes": {
 "company_attributes": {
 "customer_id": 10,
 "company_id": 2,
 "status": 0,
 "job_title": "Sales Rep",
 "telephone": "123-123-1122"
 },
 "is_subscribed": false
 }
}
answered Mar 25 at 6:02

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.