Step-by-Step Guide: Creating a Company via REST API in Magento B2B (Adobe Commerce)
Step-by-Step Guide: Creating a Company via REST API in Magento B2B (Adobe Commerce)
Creating a company in Adobe Commerce (Magento) via REST API involves a few straightforward steps. This process is essential for integrating B2B functionalities into your e-commerce platform.
Table Of Content
Step-by-Step Guide: Creating a Company via REST API in Magento B2B (Adobe Commerce)
1. Create a Customer Account
First, set up a customer who will act as the company's superuser. This step is optional if you already have a suitable customer account.
HTTP Method: POST
Endpoint: <HOST_URL>/rest/<storeCode>/V1/customers</code>
Headers:
- Authorization: Bearer
<ADMIN_TOKEN>
Request Payload:
{
"customer": {
"dob": "1991-05-27",
"email": "[email protected]",
"firstname": "John",
"lastname": "Doe",
"website_id": 1
},
"password": "YourSecurePassword"
}
Response:
{
"id": 5,
"group_id": 1,
"created_at": "2025-01-13 11:12:18",
"updated_at": "2025-01-13 11:12:18",
"created_in": "Default Store View",
"dob": "1991-05-27",
"email": "[email protected]",
"firstname": "John",
"lastname": "Doe",
"store_id": 1,
"website_id": 1,
"addresses": [],
"disable_auto_group_change": 0,
"extension_attributes": {
"is_subscribed": false
}
}
Note the id in the response; this is the super_user_id for the company.
2. Create the Company
With the customer created, proceed to set up the company.
HTTP Method: POST
Endpoint: <HOST_URL>/rest/<storeCode>/V1/company
Headers:
- Authorization: Bearer
<ADMIN_TOKEN>
Request Payload:
{
"company": {
"status": 1,
"company_name": "emmo",
"company_email": "[email protected]",
"street": ["123 Business Rd"],
"city": "Commerce City",
"country_id": "US",
"region": "CA",
"region_id": 12,
"postcode": "90001",
"telephone": "1234567890",
"super_user_id": 5,
"customer_group_id": 15
}
}
Response
{
"id": 12,
"status": 1,
"company_name": "Test Wholesale",
"company_email": "[email protected]",
"street": ["123 Business Rd"],
"city": "Commerce City",
"country_id": "US",
"region_id": 12,
"postcode": "90001",
"telephone": "1234567890",
"customer_group_id": 15,
"sales_representative_id": 2,
"super_user_id": 5,
"extension_attributes": {
"quote_config": {
"company_id": "12",
"is_quote_enabled": false
}
}
}
Field | Description |
---|---|
company_name |
Name of the company |
company_email |
Contact email for the company |
street |
Street address |
city |
city |
country_id |
Country code (e.g., "US") |
region |
State or region |
postcode |
Postal code |
telephone |
Contact number |
customer_group_id |
Shared catalog ID (e.g., 15) |
super_user_id |
ID of the superuser (from step 1) |
Ensure all required fields are included in your request. The customer_group_id corresponds to the company's shared catalog ID; for instance, 1 represents the default shared catalog. The super_user_id should match the customer ID created earlier.
Tip
To enhance your eCommerce store’s performance with Magento, focus on optimizing site speed by utilizing Emmo themes and extensions. These tools are designed for efficiency, ensuring your website loads quickly and provides a smooth user experience. Start leveraging Emmo's powerful solutions today to boost customer satisfaction and drive sales!
FAQs
What Is the Purpose of Creating a Company via REST API in Magento B2B?
Creating a company via the REST API in Magento B2B (Adobe Commerce) enables merchants to efficiently set up B2B accounts, manage corporate buyers, and automate account creation processes for large-scale businesses.
What Are the Prerequisites for Using the REST API to Create a Company?
Before using the REST API to create a company, ensure that you have an admin token for authentication and that the Magento B2B extension is properly installed and configured on your Adobe Commerce platform.
Which Endpoint Should Be Used to Create a Company via REST API?
Use the following endpoint to create a company via REST API: <HOST_URL>/rest/<storeCode>/V1/company
. Ensure you have the necessary authorization token to access this endpoint.
What Information Is Required to Create a Company via REST API?
The following information is required in the request payload when creating a company via REST API:
- Company Name
- Company Email
- Street Address
- City
- Country Code
- Region
- Postal Code
- Telephone
- Super User ID
- Customer Group ID
How Do You Generate the Super User ID for a Company?
To generate the Super User ID, create a customer account using the <HOST_URL>/rest/<storeCode>/V1/customers
endpoint. The generated customer ID will be used as the Super User ID in the company creation request.
What Are Common Issues When Creating a Company via REST API?
Common issues include:
- Missing required fields in the request payload.
- Invalid authorization token.
- Incorrect customer group ID.
- API endpoint misconfiguration.
How Do You Verify If a Company Has Been Successfully Created?
You can verify a company's successful creation by querying the company details using the <HOST_URL>/rest/<storeCode>/V1/company/<companyId>
endpoint. The response will provide the company's information, including its status and associated users.
Can You Manually Update a Company's Information via REST API?
Yes, you can manually update a company's information via the REST API using the <HOST_URL>/rest/<storeCode>/V1/company/<companyId>
endpoint. Ensure that the payload includes the updated fields and that the request is authenticated.
What Are Best Practices for Using the REST API in Magento B2B?
Best practices include:
- Always use secure connections (HTTPS).
- Regularly rotate and secure API tokens.
- Validate request payloads to ensure required fields are included.
- Monitor and log API interactions for troubleshooting.