create warehouse with magento api

Magento 2 API (Updated 2024): How to Create a Warehouse

The warehouse is the place where you store your products physically. In Magento 2 API, you can create both physical and virtual sources for your inventory. Using Magento API to find out How to create a warehouse and manage them with ease. Once you have created a warehouse, it can only be modified, disabled, but can not be deleted.

Create a warehouse

While creating a new warehouse, this information will be needed:

  • name
  • source_code
  • country id
  • postcode
  • latitude
  • longitude

And other address-related attributes for Distance Priority Source Selection Algorithm (SSA) to calculate the distance between the source and the shipping address. Moreover, the value assigned to source_code cannot be changed.

Endpoint:

POST <host>/rest/default/V1/inventory/sources

Authorization: Admin – Bearer token

Payload:

{
   "source" : {
      "name" : "Northeast Warehouse",
      "source_code" : "ne_wh",
      "postcode" : "07306",
      "enabled" : true,
      "contact_name" : "Ethan Carter",
      "country_id" : "US",
      "street": "645 Newark Ave.",
      "city" : "Jersey City",
      "region_id": 41,
      "region": "New Jersey",
      "latitude": 40.733790,
      "longitude": -74.058720
   }
}Code language: JSON / JSON with Comments (json)

To create a pickup location using this sample:

{
   "source" : {
      "name" : "Brooklyn Store",
      "source_code" : "brooklyn",
      "postcode" : "11211",
      "enabled" : true,
      "contact_name" : "Tai Hozie",
      "country_id" : "US",
      "street": "263 S 4th St",
      "city" : "Brooklyn",
      "region_id": 43,
      "region": "New York",
      "latitude": 40.710070,
      "longitude": -73.957160,
      "phone": "555 737-8088",
      "extension_attributes": {
        "is_pickup_location_active": true,
        "frontend_name": "Brooklyn (Williamsburg) Store",
        "frontend_description": "Williamsburg, Brooklyn"
    }
  }
}Code language: JSON / JSON with Comments (json)

For virtual and downloadable product use this sample:

{
   "source" : {
      "name" : "HQ",
      "source_code" : "hq",
      "postcode" : "10022",
      "enabled" : true,
      "contact_name" : "Francine Helen",
      "country_id" : "US",
      "street": "909 3rd Ave",
      "city" : "New York",
      "region_id": 43,
      "region": "New York",
      "latitude": 40.7571,
      "longitude": -73.9657
   }
}Code language: JSON / JSON with Comments (json)

Response:

Magento returns an empty array.

How to create a warehouse with magento api

Verify the result

Log in to your Magento admin and view all the warehouses/sources you have created. Go to Stores > Inventory > Sources.

view warehouse in admin

I have shown you how to create a simple warehouse with Magento API. You can apply this to create brick-and-mortar stores, distribution centers, and drop shippers as well. Check how to create an integration with Magento here. If you have any questions please leave a comment in the section below, or refer to Magento DevDocs.