Skip to content

Add Customer Via REST API with a company

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.