Cookies help us enhance your experience on our site by storing
information about your preferences and interactions. You can customize your
cookie settings by choosing which cookies to allow. Please note that disabling
certain cookies might impact the functionality and features of our services,
such as personalized content and suggestions.
Cookie Policy
These cookies are strictly necessary for the site to work and may not be disabled.
Cookie name
Description
Lifetime
Provider
_ce.clock_data
Store the difference in time from the server's time and the current browser.
1 day
Crazy Egg
_ce.clock_event
Prevent repeated requests to the Clock API.
1 day
Crazy Egg
_ce.irv
Store isReturning value during the session
Session
Crazy Egg
_ce.s
Track a recording visitor session unique ID, tracking host and start time
1 year
Crazy Egg
_hjSessionUser_2909345
Store a unique user identifier to track user sessions and interactions for analytics purposes.
1 year
HotJar
_hjSession_2909345
Store session data to identify and analyze individual user sessions.
1 day
HotJar
apt.uid
Store a unique user identifier for tracking and personalization.
1 year
Mageplaza
cebs
Store user preferences and settings.
Session
Mageplaza
cf_clearance
Store a token that indicates a user has passed a Cloudflare security challenge.
1 year
Cloudflare
crisp-client
The crisp-client/session cookie is used to identify and maintain a user session within the Crisp platform. It allows the live chat system to recognize returning users, maintain chat history, and ensure continuity in customer service interactions.
Session
Crisp
_ga
Store a unique client identifier (Client ID) for tracking user interactions on the
2 years
Google
_ga_7B0PZZW26Z
Store session state information for Google Analytics 4.
2 years
Google
_ga_JTRV42NV3L
Store session state information for Google Analytics 4.
2 years
Google
_ga_R3HWQ50MM4
Store a unique client identifier (Client ID) for tracking user interactions on the website.
2 years
Google
_gid
Store a unique client identifier (Client ID) for tracking user interactions on the website.
1 day
Google
_gat_UA-76130628-1
Throttle the request rate to Google Analytics servers.
1 day
Google
Advertising cookies
Advertising cookies deliver ads relevant to your interests, limit ad frequency, and measure ad effectiveness.
Advertising cookies deliver ads relevant to your interests, limit ad frequency, and measure ad effectiveness.
Cookie name
Description
Lifetime
Provider
_gcl_au
The cookie is used by Google to track and store conversions.
1 day
Google
__Secure-3PAPISID
This cookie is used for targeting purposes to build a profile of the website visitor's interests in order to show relevant and personalized Google advertising.
2 years
Google
HSID
This security cookie is used by Google to confirm visitor authenticity, prevent fraudulent use of login data and protect visitor data from unauthorized access.
2 years
Google
__Secure-1PSID
This cookie is used for targeting purposes to build a profile of the website visitor's interests in order to show relevant and personalized Google advertising.
2 years
Google
SID
This security cookie is used by Google to confirm visitor authenticity, prevent fraudulent use of login data and protect visitor data from unauthorized access.
2 years
Google
APISID
This cookie is used by Google to display personalized advertisements on Google sites, based on recent searches and previous interactions.
2 years
Google
__Secure-1PAPISID
This cookie is used for targeting purposes to build a profile of the website visitor's interests in order to show relevant and personalized Google advertising.
2 years
Google
__Secure-3PSID
This cookie is used for targeting purposes to build a profile of the website visitor's interests in order to show relevant and personalized Google advertising.
2 years
Google
SSID
This cookie is used by Google to display personalized advertisements on Google sites, based on recent searches and previous interactions.
2 years
Google
SAPISID
This cookie is used by Google to display personalized advertisements on Google sites, based on recent searches and previous interactions.
2 years
Google
__Secure-3PSIDTS
This cookie collects information about visitor's interactions with Google services and ads. It is used to measure advertising effectiveness and deliver personalised content based on interests. The cookie contains a unique identifier.
2 years
Google
__Secure-1PSIDTS
This cookie collects information about visitor's interactions with Google services and ads. It is used to measure advertising effectiveness and deliver personalised content based on interests. The cookie contains a unique identifier.
2 years
Google
SIDCC
This security cookie is used by Google to confirm visitor authenticity, prevent fraudulent use of login data, and protect visitor data from unauthorized access.
3 months
Google
__Secure-1PSIDCC
This cookie is used for targeting purposes to build a profile of the website visitor's interests in order to show relevant and personalized Google advertising.
1 year
Google
__Secure-3PSIDCC
This cookie is used for targeting purposes to build a profile of the website visitor's interests in order to show relevant and personalized Google advertising.
1 year
Google
1P_JAR
This cookie is a Google Analytics Cookie created by Google DoubleClick and used to show personalized advertisements (ads) based on previous visits to the website.
1 month
Google
NID
Show Google ads in Google services for signed-out users.
6 months
Google
Analytics cookies
Analytics cookies collect information and report website usage statistics without personally identifying individual visitors to Google.
Analytics cookies collect information and report website usage statistics without personally identifying individual visitors to Google.
Cookie name
Description
Lifetime
Provider
_dc_gtm
Manage and deploy marketing tags through Google Tag Manager.
1 year
Google
1P_JAR
Gather website statistics and track conversion rates for Google AdWords campaigns.
1 month
Google
AEC
1 month
Google
ar_debug
Debugging purposes related to augmented reality (AR) functionalities.
1 month
Doubleclick
IDE
The IDE cookie is used by Google DoubleClick to register and report the user's actions after viewing or clicking on one of the advertiser's ads with the purpose of measuring the effectiveness of an ad and to present targeted ads to the user.
1 year
Doubleclick
ad_storage
Enables storage, such as cookies (web) or device identifiers (apps), related to advertising.
1 year
Google
ad_user_data
Sets consent for sending user data to Google for online advertising purposes.
1 year
Google
ad_personalization
Sets consent for personalized advertising.
1 year
Google
analytics_storage
Enables storage, such as cookies (web) or device identifiers (apps), related to analytics, for example, visit duration.
How to Create Custom REST API in Magento 2 - Mageplaza
How to Create Custom REST API in Magento 2
Vinh Jacker|03-17-2025
Magento 2 Create API means helping online retailers generate an Application Programming Interface for the own using. The API is a set of routines, protocols and other tools to design software applications. Thus, API is a required element to connect among the data if you ask for any program or service from other websites. With the creation of API in Magento 2, you can easily get all building blocks to initiate a program successfully.
To support better in Magento 2 module development, Mageplaza team attempts to build API tester in your hello world module of Magento 2 module development series. http://<magento_host>/swagger
What is API in Magento 2?
API stands for Application Programming Interface to allow you access the data from an application. API can be called as a middleman between a programmer and an application. When the programmer calls for a request via the middleman, if the request is approved, the right data will be turned back.
As eCommerce stores basing on Magento 2 platform, you should look at two architectural kinds of the web APIs: REST (Representational State Transfer) and SOAP (Simple Object Access Protocol). However, in the official documentation, they only come with raw curl request without any example. In order to connect and use Magento 2 API effectively, this topic will show you PHP examples in specific.
How to create custom REST API in Magento 2 | Detailed guide
Step 1: A custom module creation
Start by creating a custom module. In this example, we’ll use the namespace Dev_RestApi.
Create the module.xml and registration.php files within your module directory app/code/Dev/RestApi. The module.xml file defines your module and its dependencies.
Where to show:
The URL for this endpoint would be <domain>/rest/<store_code>/V1/rest_dev/getProduct/:id.
The method determines the request type (GET, POST, PUT, DELETE).
The service class and method define the interface to be called when the endpoint is reached.
ACL resources can be set using tags.
Step 4: Di.xml creation
Create a di.xml file in app/code/Dev/RestApi/etc/di.xml for interface configuration.
Define interfaces for requests and responses.
Example interface for requests in app/code/Dev/RestApi/Api/RequestItemInterface.php
<?php
namespace Dev\RestApi\Api;
interface RequestItemInterface
{
const DATA_ID = 'id';
const DATA_DESCRIPTION = 'description';
/**
* @return int
*/
public function getId();
/**
* @return string
*/
public function getDescription();
/**
* @param int $id
* @return $this
*/
public function setId(int $id);
/**
* @param string $description
* @return $this
*/
public function setDescription(string $description);
}
Example interface for responses in app/code/Dev/RestApi/Api/ResponseItemInterface.php.
<?php
namespace Dev\RestApi\Api;
interface ResponseItemInterface
{
const DATA_ID = 'id';
const DATA_SKU = 'sku';
const DATA_NAME = 'name';
const DATA_DESCRIPTION = 'description';
/**
* @return int
*/
public function getId();
/**
* @return string
*/
public function getSku();
/**
* @return string
*/
public function getName();
/**
* @return string|null
*/
public function getDescription();
/**
* @param int $id
* @return $this
*/
public function setId(int $id);
/**
* @param string $sku
* @return $this
*/
public function setSku(string $sku);
/**
* @param string $name
* @return $this
*/
public function setName(string $name);
/**
* @param string $description
* @return $this
*/
public function setDescription(string $description);
}
Establish the “ProductRepositoryInterface” within the designated file path “app/code/Dev/RestApi/Api/ProductRepositoryInterface.php”.
<?php
namespace Dev\RestApi\Api;
interface ProductRepositoryInterface
{
/**
* Return a filtered product.
*
* @param int $id
* @return \Dev\RestApi\Api\ResponseItemInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getItem(int $id);
/**
* Set descriptions for the products.
*
* @param \Dev\RestApi\Api\RequestItemInterface[] $products
* @return void
*/
public function setDescription(array $products);
}
Step 6. Models creation
Models serve the function of defining classes that adhere to interfaces and effectively managing data.
In this example, we’ve created models for requesting, responding to, and processing data. Each model includes two methods: getItem, which retrieves product details depending on a given product ID, and setDescription, which updates the product description.
app/code/Dev/RestApi/Model/Api/RequestItem.php:
<?php
namespace Dev\RestApi\Model\Api;
use Dev\RestApi\Api\RequestItemInterface;
use Magento\Framework\DataObject;
/**
* Class RequestItem
*/
class RequestItem extends DataObject implements RequestItemInterface
{
public function getId() : int
{
return $this->_getData(self::DATA_ID);
}
public function getDescription() : string
{
return $this->_getData(self::DATA_DESCRIPTION);
}
/**
* @param int $id
* @return $this
*/
public function setId(int $id) : mixed
{
return $this->setData(self::DATA_ID, $id);
}
/**
* @param string $description
* @return $this
*/
public function setDescription(string $description) : mixed
{
return $this->setData(self::DATA_DESCRIPTION, $description);
}
}
app/code/Dev/RestApi/Model/Api/ResponseItem.php:
<?php
namespace Dev\RestApi\Model\Api;
use Dev\RestApi\Api\ResponseItemInterface;
use Magento\Framework\DataObject;
/**
* Class ResponseItem
*/
class ResponseItem extends DataObject implements ResponseItemInterface
{
public function getId() : int
{
return $this->_getData(self::DATA_ID);
}
public function getSku() : string
{
return $this->_getData(self::DATA_SKU);
}
public function getName() : string
{
return $this->_getData(self::DATA_NAME);
}
public function getDescription() : string
{
return $this->_getData(self::DATA_DESCRIPTION);
}
/**
* @param int $id
* @return $this
*/
public function setId(int $id) : mixed
{
return $this->setData(self::DATA_ID, $id);
}
/**
* @param string $sku
* @return $this
*/
public function setSku(string $sku) : mixed
{
return $this->setData(self::DATA_SKU, $sku);
}
/**
* @param string $name
* @return $this
*/
public function setName(string $name) : mixed
{
return $this->setData(self::DATA_NAME, $name);
}
/**
* @param string $description
* @return $this
*/
public function setDescription(string $description) : mixed
{
return $this->setData(self::DATA_DESCRIPTION, $description);
}
}
To implement changes, update .xml files, and constructors, or add new classes, run bin/magento setup:upgrade or bin/magento setup:di:compile from the Adobe Commerce or Magento Open Source directory.
Step 7: Custom endpoint testing
Use any REST client (e.g., Postman) to send calls to your custom API.
Obtain an admin authorization token (required for all calls).
Test your endpoints to ensure they work as expected.
To test your custom API, you must first obtain an Admin Token for authorization. Follow our Get Admin Token Magento 2 API guide to learn how to generate this token.
GET endpoint testing
This example demonstrates the usage of sample data associated with product ID 1, retrievable from the endpoint http://local.magentoee.com/rest/V1/rest_dev/getProduct/1.
Demand to test the GET endpoint:
GET <domain>/rest/V1/<store_code>/rest_dev/getProduct/<product_id>
Response:
{
"id": 1,
"sku": "24-MB01",
"name": "Joust Duffle Bag",
"description": "<p>The sporty Joust Duffle Bag can't be beat - not in the gym, not on the luggage carousel, not anywhere. Big enough to haul a basketball or soccer ball and some sneakers with plenty of room to spare, it's ideal for athletes with places to go.<p>\n<ul>\n<li>Dual top handles.</li>\n<li>Adjustable shoulder strap.</li>\n<li>Full-length zipper.</li>\n<li>L 29\" x W 13\" x H 11\".</li>\n</ul>"
}
The PUT endpoint testing
Demand to test the PUT endpoint:
PUT <domain>/rest/V1/<store_code>/rest_dev/setDescription
If you want to ensure the process is smooth and successful, it’s better to consider a Magento API Integration service. You’ll save a lot of time and effort, while focusing on other essential business aspects.
By using the Magento API Integration service by Mageplaza, you can:
Connect your store with other third-party platforms to streamline processes
Carry out various tasks and share data via one single dashboard
Eliminate manual and tedious tasks
Improve customer experience
To make sure you’re completely satisfied with the result, we offer free two-month support after the integration process. Our experts also lead your project from start to finish, so you don’t need to worry about anything!
Jacker is the Chief Technology Officer (CTO) at Mageplaza, bringing over 10 years of experience in Magento, Shopify, and other eCommerce platforms. With deep technical expertise, he has led numerous successful projects, optimizing and scaling online stores for global brands. Beyond his work in eCommerce development, he is passionate about running and swimming.
Discover a step-by-step framework for effective social media marketing. Learn how to optimize content, run ads, track KPIs, and future-proof your strategy across all major platforms.
Discover a step-by-step framework for effective social media marketing. Learn how to optimize content, run ads, track KPIs, and future-proof your strategy across all major platforms.
Discover a step-by-step framework for effective social media marketing. Learn how to optimize content, run ads, track KPIs, and future-proof your strategy across all major platforms.
Discover a step-by-step framework for effective social media marketing. Learn how to optimize content, run ads, track KPIs, and future-proof your strategy across all major platforms.