Skip to Content
MailerLite
E-commerce API

E-commerce Categories Products API

Attach products to categories and manage the many-to-many relationship between them.

Assign/unassign products to categories

Get the products of a category

If you want to get the products for a particular shop and a category, send this GET request

GET https://connect.mailerlite.com/api/ecommerce/shops/:shop_id/categories/:category_id/products

Request parameters

ParameterTypeRequiredLimitations
shop_idintegeryesMust provide valid shop id
category_idintegeryesMust provide category id
limitintegernoDefaults to 100. Maximum 1000, larger values are capped
pageintegernoDefaults to 1

Products are returned in ascending order of their ID.

Response

{
  "data": [
    {
      "id": "31986843543567834",
      "name": "Product name",
      "price": 123.4,
      "url": "https://shop-url.com/product-name",
      "image": "https://shop-url.com/product-image.jpg",
      "exclude_from_automations": false,
      "enabled": true,
      "categories": [
        {
          "id": "1234566457534276",
          "name": "Category 1",
          "exclude_from_automations": false,
          "created_at": "2021-09-01 14:03:50",
          "updated_at": "2021-09-01 14:03:50"
        },
        {
          "id": "1234566457534278",
          "name": "Category 2",
          "exclude_from_automations": false,
          "created_at": "2021-09-01 14:03:50",
          "updated_at": "2021-09-01 14:03:50"
        }
      ]
    }
  ],
  "links": {
    "first": "https://connect.mailerlite.com/api/ecommerce/shops/:shop_id/categories/:category_id/products?page=1",
    "last": "https://connect.mailerlite.com/api/ecommerce/shops/:shop_id/categories/:category_id/products?page=1",
    "prev": null,
    "next": null
  },
  "meta": {
    "current_page": 1,
    "from": 1,
    "last_page": 1,
    "links": [
      {
        "url": null,
        "label": "« Previous",
        "active": false
      },
      {
        "url": "https://connect.mailerlite.com/api/ecommerce/shops/:shop_id/categories/:category_id/products?page=1",
        "label": "1",
        "active": true
      },
      {
        "url": null,
        "label": "Next »",
        "active": false
      }
    ],
    "path": "https://connect.mailerlite.com/api/ecommerce/shops/:shop_id/categories/:category_id/products",
    "per_page": 100,
    "to": 1,
    "total": 1
  }
}

Assign a product to a category

If you want to assign a product to a category for a given shop, send this PUT request

PUT https://connect.mailerlite.com/api/ecommerce/shops/:shop_id/categories/:category_id/products/:product_id

Request body

ParameterTypeRequiredLimitations
shop_idintegeryesMust provide valid shop id
category_idintegeryesMust provide category id
product_idintegeryesMust provide product id

Response

If the product was assigned to the category:

Response Code: 200 OK
{
  "data": {
    "id": "31986843543567834",
    "name": "Product name",
    "price": 123.4,
    "url": "https://shop-url.com/product-name",
    "image": "https://shop-url.com/product-image.jpg",
    "exclude_from_automations": false,
    "enabled": true,
    "categories": [
      {
        "id": "1234566457534276",
        "name": "Category 1",
        "exclude_from_automations": false,
        "created_at": "2021-09-01 14:03:50",
        "updated_at": "2021-09-01 14:03:50"
      },
      {
        "id": "1234566457534278",
        "name": "Category 2",
        "exclude_from_automations": false,
        "created_at": "2021-09-01 14:03:50",
        "updated_at": "2021-09-01 14:03:50"
      }
    ]
  }
}

Error

Response Code: 422 Unprocessable Entity

The error response will contain information about the invalid data.

{
  "message": "The given data was invalid.",
  "errors": {
    "product_id": ["The product id must be provided."]
  }
}

Assign multiple categories to a product

If you want to assign multiple categories to a product for a given shop, send this PUT request

PUT https://connect.mailerlite.com/api/ecommerce/shops/:shop_id/products/:product_id/categories/multiple

Request body

ParameterTypeRequiredLimitations
shop_idintegeryesMust provide valid shop id
product_idintegeryesMust provide product id
categoriesarrayyesCategory ids, max 100
replacebooleannoIf true, removes the product from categories not in the list
{
  "categories": ["1234566457534276", "1234566457534278"],
  "replace": false
}

Response

If the categories were assigned to the product:

Response Code: 200 OK
{
  "data": {
    "id": "31986843543567834",
    "name": "Product name",
    "price": 123.4,
    "url": "https://shop-url.com/product-name",
    "image": "https://shop-url.com/product-image.jpg",
    "exclude_from_automations": false,
    "categories": [
      {
        "id": "1234566457534276",
        "name": "Category 1",
        "exclude_from_automations": false,
        "created_at": "2021-09-01 14:03:50",
        "updated_at": "2021-09-01 14:03:50"
      },
      {
        "id": "1234566457534278",
        "name": "Category 2",
        "exclude_from_automations": false,
        "created_at": "2021-09-01 14:03:50",
        "updated_at": "2021-09-01 14:03:50"
      }
    ]
  }
}

Error

Response Code: 422 Unprocessable Entity

The error response will contain information about the invalid data.

{
  "message": "The given data was invalid.",
  "errors": {
    "categories": ["The categories field must not have more than 100 items."]
  }
}
Response Code: 404 Not Found

Returned when a category does not belong to the shop.

Unassign a product from a category

If you want to unassign a product from a category for a given shop, send this DELETE request

DELETE https://connect.mailerlite.com/api/ecommerce/shops/:shop_id/categories/:category_id/products/:product_id

Request parameters

ParameterTypeRequiredLimitations
shop_idintegeryesMust provide valid shop id
category_idintegeryesMust provide category id
product_idintegeryesMust provide product id

Response

Response code: 200 OK
{
  "id": "31986843543567834",
  "name": "Product name",
  "price": 123.4,
  "url": "https://shop-url.com/product-name",
  "image": "https://shop-url.com/product-image.jpg",
  "exclude_from_automations": false,
  "enabled": true,
  "categories": [
    {
      "id": "1234566457534276",
      "name": "Category 1",
      "exclude_from_automations": false,
      "created_at": "2021-09-01 14:03:50",
      "updated_at": "2021-09-01 14:03:50"
    },
    {
      "id": "1234566457534278",
      "name": "Category 2",
      "exclude_from_automations": false,
      "created_at": "2021-09-01 14:03:50",
      "updated_at": "2021-09-01 14:03:50"
    }
  ]
}

Error

Response code: 404 Not Found

On this page