How To

How to Get Quote Information using REST API in Magento 2

Hello Magento Friends,

Hope you are doing great. In this article, let’s find out How to Get Quote Information using REST API in Magento 2. Before starting with the steps, review our previous blog, Magento 2: Append Block to Specific Container Dynamically.

Introduction:

Magento 2 store owners can allow customers to send a quote for a product. When a customer sends a quote it is essential for store owners to decide the final price and revert back to customers. Manage customers’ quotes effortlessly by integrating Email Quote Pro Extension for Magento 2.

Before further processing, the store owners should first get the quote information. REST API is used to fetch data by sending requests and receiving responses. Let us know How to Get Quote Information using REST API in Magento 2.

Steps to Get Quote Information using REST API in Magento 2:

Step 1: Create getquotedetails.php in the Magento root directory and add the below code.

<?php
 $admindata = array("username" => "admin", "password" => "admin@123");
 $baseUrl = "http://yourdomain"; // your magento base url
 $ch = curl_init($baseUrl."/rest/V1/integration/admin/token");
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($admindata));
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($admindata))));

 $token = curl_exec($ch);

 $ch = curl_init($baseUrl."/rest/V1/carts/1"); // change cart id 
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));
 $result = curl_exec($ch);
 $result = json_decode($result, 1);
 echo '<pre>';
 print_r($result);
?>

Step 2: After that run URL as below

 https://yourdomain/getquotedetails.php

Conclusion:

Hence, with the execution of the above code, you will be able to Get Quote Information using REST API in Magento 2. Also, check out How to Get Order Details using REST API in Magento 2.

For any difficulties, feel free to mention them in the comment part below. Keep sharing and keep in touch with us. See you again with another solution.

Happy Coding!

Click to rate this post!
[Total: 5 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate ?️ Certified Magento Developer?‍?. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.?

Recent Posts

How to Create a Shopify Draft Order in Shopify Remix Using GraphQL?

Shopify's Draft Orders feature is an essential tool for merchants, allowing them to create orders…

19 hours ago

How to Use CSS with Shopify Remix Vite?

CSS (Cascading Style Sheets) is essential in web development to create visually appealing and responsive…

2 days ago

Latest Hyvä Theme Trends to Elevate your Magento UI/UX

Your eCommerce website theme is highly important for your business's online success as it reflects…

2 days ago

Use Hyvä Products at their Full Potential

Hyvä represents more than just a theme; it is a comprehensive suite of extensions and…

3 days ago

Magento 2: Add Number of Products Displayed Per Page in Invoice PDF

Hello Magento mates, Invoices are critical documents in every eCommerce business, providing details of product…

4 days ago

Magento 2: How to Call phtml Based on Selection of Payment Method at Multishipping Payment

Hello Magento Friends, Multishipping in Magento 2 allows customers to split their orders into multiple…

7 days ago