Adobe Commerce Company’s feature covers wholesale B2B functionality for the store owners.
The company feature is robust and you can create a company from the front end via creating a company account, Admin panel new Company, GraphQL as well as using REST API.
I will provide you step by step guide to creating a new company using REST API.
Before creating Company, you just need to create a customer to assign that customer as a superuser for the company.
This step is optional if you have already created a company,
Create Customer using Magento API,
Action: POST
URL: <HOST_URL>/rest/<storeCode>/V1/customers
HEADER: Authorization: Bearer <ADMIN_TOKEN>
Request Payload:
{
"customer": {
"dob": "05/27/1991",
"email": "rbj@jesadiya.com",
"firstname": "Rakesh",
"lastname": "Jesadiya",
"website_id": 2
},
"password": "YOUR_PASSWORD"
}
Response:
{
"id": 5,
"group_id": 1,
"created_at": "2021-11-03 11:12:18",
"updated_at": "2021-11-03 11:12:18",
"created_in": "Default Store View",
"dob": "1991-05-27",
"email": "rbj@jesadiya.com",
"firstname": "Rakesh",
"lastname": "Jesadiya",
"store_id": 1,
"website_id": 1,
"addresses": [],
"disable_auto_group_change": 0,
"extension_attributes": {
"is_subscribed": false
}
}
Here New customer is generated and the new id will be 5.
Now We are just moving to the original post of Create Company API stuff.
Action: POST
URL: <HOST_URL>/rest/<storeCode>/V1/company
HEADER: Authorization:Bearer <ADMIN_TOKEN>
Request Payload:
{
"company": {
"status": 1,
"company_name": "Test Wholesale",
"company_email": "testadmin@fake.com",
"street": [
"Test Test"
],
"city": "San Francisco",
"country_id": "US",
"region": "CA",
"region_id": "12",
"postcode": "99999",
"telephone": "45645645",
"super_user_id": 5,
"customer_group_id": 15
}
}
Below are the list of required fields in request body (*),
- company_name
- company_email
- street
- city
- country_id
- region
- postcode
- telephone
- customer_group_id
- super_user_id.
customer_group_id is the company’s shared catalog Id. If you pass 1 that means the default shared catalog. Here we have assigned a value is 15 for our custom customer group id.
super_user_id is the customer id assigned as superuser of the company.
Response:
Response:
{
"id": 12,
"status": 1,
"company_name": "Test Wholesale",
"company_email": "testadmin@fake.com",
"street": [
"Test Test"
],
"city": "San Francisco",
"country_id": "US",
"region_id": "12",
"postcode": "99999",
"telephone": "4155551212",
"customer_group_id": 15,
"sales_representative_id": 2,
"reject_reason": null,
"rejected_at": null,
"super_user_id": 5,
"extension_attributes": {
"quote_config": {
"company_id": "12",
"is_quote_enabled": false
}
}
}
