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.
-
1yeah, it says here - developer.adobe.com/commerce/webapi/rest/b2b/company-users you can't add company id directly.rex– rex2025年03月24日 20:25:53 +00:00Commented Mar 24 at 20:25
1 Answer 1
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
}
}
Explore related questions
See similar questions with these tags.