Today, we will learn how to get the product list from a Magento 2 website by using the REST API and GraphQL.
1. Get Product List 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)

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

For example:


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.

For example:
That’s how we can get the product list data using the Magento REST API.
2. Get Product List 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 } } } }

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 which has data like this:

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