Hyvä Theme is Now Open Source: What This Means for Magento Community - Mageplaza
Hyvä is now Open Source and free. Discover what changed, what remains commercial, how it impacts the Magento ecosystem, and how to maximize its full potential.
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
Cookie PolicyThese cookies are strictly necessary for the site to work and may not be disabled.
InformationThese 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 | |
| _ga_7B0PZZW26Z | Store session state information for Google Analytics 4. | 2 years | |
| _ga_JTRV42NV3L | Store session state information for Google Analytics 4. | 2 years | |
| _ga_R3HWQ50MM4 | Store a unique client identifier (Client ID) for tracking user interactions on the website. | 2 years | |
| _gid | Store a unique client identifier (Client ID) for tracking user interactions on the website. | 1 day | |
| _gat_UA-76130628-1 | Throttle the request rate to Google Analytics servers. | 1 day |
Advertising cookies deliver ads relevant to your interests, limit ad frequency, and measure ad effectiveness.
InformationAdvertising 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 | |
| __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 | |
| 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 | |
| __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 | |
| 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 | |
| APISID | This cookie is used by Google to display personalized advertisements on Google sites, based on recent searches and previous interactions. | 2 years | |
| __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 | |
| __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 | |
| SSID | This cookie is used by Google to display personalized advertisements on Google sites, based on recent searches and previous interactions. | 2 years | |
| SAPISID | This cookie is used by Google to display personalized advertisements on Google sites, based on recent searches and previous interactions. | 2 years | |
| __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 | |
| __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 | |
| 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 | |
| __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 | |
| __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 | |
| 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 | |
| NID | Show Google ads in Google services for signed-out users. | 6 months |
Analytics cookies collect information and report website usage statistics without personally identifying individual visitors to Google.
InformationAnalytics 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 | |
| 1P_JAR | Gather website statistics and track conversion rates for Google AdWords campaigns. | 1 month | |
| AEC | 1 month | ||
| 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 | |
| ad_user_data | Sets consent for sending user data to Google for online advertising purposes. | 1 year | |
| ad_personalization | Sets consent for personalized advertising. | 1 year | |
| analytics_storage | Enables storage, such as cookies (web) or device identifiers (apps), related to analytics, for example, visit duration. | 1 year |
Magento 2 is a useful tool for creating and managing online stores. To enhance its capabilities, it often needs to connect with external services, APIs, or other servers. This is when cURL becomes necessary. cURL allows Magento 2 developers to perform HTTP requests programmatically, enabling them to transfer data from other sources or send data to them. In this article, we will explore how to use cURL in Magento 2.
First of all, it is necessary to create an instance of \Magento\Framework\HTTP\Client\Curl within Constructor as illustrated below:
/**
* @var \Magento\Framework\HTTP\Client\Curl
*/
protected $_curl;
/**
* Data constructor.
*
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Framework\HTTP\Client\Curl $curl
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\HTTP\Client\Curl $curl
) {
$this->_curl = $curl;
parent::__construct($context);
}
For GET requests, use the below-mentioned code:
//get method
$this->_curl->get($url);
//response will contain the output of curl request
$response = $this->_curl->getBody();
Use the following code snippet to make a POST request:
//post method
$this->_curl->post($url, $params);
//response will contain the output of curl request
$response = $this->_curl->getBody();
In the above code, $url holds the endpoint URL, $params is an array for extra URL parameters, and $response contains the curl request response.
Besides, you can add headers, basic authorization, additional cURL options, and cookies in your cURL request. You need to ensure these methods are set before using GET or POST method. Detailed instructions on how to implement these additions are provided below.
You can set cURL headers using either addHeader or setHeaders methods.
The addheader method accepts two parameters. They are the cURL header name and the cURL header value.
$this->_curl->addHeader("Content-Type", "application/json");
$this->_curl->addHeader("Content-Length", 200);
The setHeaders method is designed to accept one parameter, specifically in the form of an array.
$headers = ["Content-Type" => "application/json", "Content-Length" => "200"];
$this->_curl->setHeaders($headers);
You can set the basic authorization by using the setCredentials method.
$userName = "UserName";
$password = "Password";
$this->_curl->setCredentials($userName, $password);
This code is equivalent to setting the CURLOPT_HTTPHEADER value to
“Authorization : “. “Basic “.base64_encode($userName.”:”.$password)
There are two methods to set the cURL options, including setOption and setOptions.
The setOption method permits the assignment of individual cURL options by accepting two parameters. They are the cURL option name and the option value.
$this->_curl->setOption(CURLOPT_RETURNTRANSFER, true);
$this->_curl->setOption(CURLOPT_PORT, 8080);
The setOptions method accepts one parameter, specifically in the form of an array.
$options = [CURLOPT_RETURNTRANSFER => true, CURLOPT_PORT => 8080];
$this->_curl->setOptions($options);
There are two methods to set the cURL cookies in cURL, including addCookie and setCookies.
The addCookie method accepts two parameters. They are the cookie name and the cookie value.
$this->_curl->addCookie("cookie-name-1", "123");
$this->_curl->addCookie("cookie-name-2", "test-cookie-value");
The setCookies method accepts one parameter, specifically in the form of an array.
$cookies = ["cookie-name-1" => "100", "cookie-name-2" => "name"];
$this->_curl->setCookies($cookies);
Understanding how to use cURL in Magento 2 opens up numerous possibilities for integrating external services, and enhancing the functionality of your e-commerce store. By following the steps in this guide, you can efficiently handle HTTP requests and ensure seamless data exchange between your Magento 2 store and external APIs.
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.
Related Post
Hyvä Theme is Now Open Source: What This Means for Magento Community - Mageplaza
Hyvä is now Open Source and free. Discover what changed, what remains commercial, how it impacts the Magento ecosystem, and how to maximize its full potential.
Holiday Marketing Hacks 2025 - How to Boost Sales for Magento 2 Stores? - Mageplaza
Discover the best 2025 holiday marketing strategies for Magento 2. Learn key trends, creative campaign ideas, and expert tips to increase seasonal sales.
Hyvä Theme is Now Open Source: What This Means for Magento Community - Mageplaza
Hyvä is now Open Source and free. Discover what changed, what remains commercial, how it impacts the Magento ecosystem, and how to maximize its full potential.
Holiday Marketing Hacks 2025 - How to Boost Sales for Magento 2 Stores? - Mageplaza
Discover the best 2025 holiday marketing strategies for Magento 2. Learn key trends, creative campaign ideas, and expert tips to increase seasonal sales.