How to Get All Products through Magento 2 API

how to get product list catalog through magento 2 api

To satisfy the increasing demands of e-commerce businesses, Magento 2 now provides Application Programming Interface (API) that lets developers work with the platform’s data. This guide will show you how to get the product list from a Magento 2 website by using the REST API and GraphQL. Let’s get started and unlock the potential of the Magento 2 API to access all products for your e-commerce needs.

Get All Products Data With REST API

You can use a tool to access the API. Here we are using Postman.

To get product list data, we need to get the access token of the admin user:

Endpoint: “http(s)://yourdomain.com/rest/V1/integration/admin/token”

Method: POST

Request:

{
	"username" : "string",
	"password" : "string"
}

Response: “token” (string)

get product list magento 2 api

Example:

Magento system will check whether that username is available or not, then the API will return the access token as a string.

using magento 2 rest api

For example:

get catalog api magento 2

If your username and password are incorrect, the API will return an error like the following:

After having the access token, we can get product list information from the API.
Endpoint: “http(s)://yourdomain.com/rest/V1/ products”
Method: GET
Request: searchCriteria.
Header: Authorization: Bearer (Token)
Response: token(string)
For example:

If the access token is correct, the API will return the customer’s information.

For example:

If the access token is incorrect, the API will return an error.

get product list in magento 2

For example:

That’s how we can get the product list data using the Magento REST API.

Bonus: Get All Products Data With GraphQL

Now, let’s move on to getting the catalog information using Magento 2 GraphQL.
Endpoint: “http(s)://yourdomain.com/rest/V1/ products”

Method: POST

Syntax:  products(
    search: String
    filter: ProductFilterInput
    pageSize: Int
    currentPage: Int
    sort: ProductSortInput
): Products

Request example:

First, write down the endpoint and your request:

{
  products(
    filter: { sku: { like: "24-WB%" } }
    pageSize: 20
    currentPage: 1
    sort: { name: DESC }
  ) {
    items {
      sku
    }
    filters {
      name
      filter_items_count
      request_var
      filter_items {
        label
        value_string
        items_count
      }
    }
  }
}
Get Product Info Using REST API In Magento 2

Response:

{
    "data": {
        "products": {
            "total_count": 26,
            "items": [
                {
                    "name": "BUNDLE: Tiny Round \"Design Your Own\" Children's Necklace for Girls (50+ Optional Charms & FREE Engraving)",
                    "sku": "Tiny Round",
                    "price": {
                        "regularPrice": {
                            "amount": {
                                "currency": "USD",
                                "value": 439.78
                            }
                        }
                    }
                }],
            "page_info": {
                "page_size": 25,
                "current_page": 1
            }
        }
    }
}

Now click run to send the request to the server.
API will return a response that has data like this:


Wrap Up

In conclusion, knowing how to get all products through the Magento 2 API allows you to efficiently manage your e-commerce data. By following the steps outlined in this blog post, you can make use of the full potential of the API and streamline your business processes. Follow the guide to take control of your product data efficiently and run your business smoothly.

Related Posts:

How To Use Custom Local Storage & Cookie Storage In Magento 2?

How To Get Categories Through Magento 2 REST API?

How To Create A Credit Memo In Magento 2 In 10 minutes

Magento 2 Product Types: Everything Merchants Should Know

Magento Product Attributes: Everything Store Owners Must Know

How To Get A Product By SKU Using GraphQL In Magento 2

2 thoughts on “How to Get All Products through Magento 2 API

Leave a Reply

Your email address will not be published. Required fields are marked *