I am trying to learn swagger in magento 2.

In core APIs of Magento 2 there is a required field cart_id.

enter image description here

enter image description here

I don't know what is this cart id and how can i find this ?


*Cart id it means Quote id you will get quote Id in your Database Under "quote" table It seems you want payment information use the below API try this for payment method :

67 is my quote Id : In your case you will get under Quote Table

GET : your-domain-url/index.php/rest/V1/carts/67/payment-methods

you will get the below resonse response : [ { "code": "checkmo", "title": "Check / Money order" } ]*

  • sorry Ankit but there is no field name as quote id in table quote ? can you explain plz – Ramkishan Suthar Sep 29 '16 at 6:55
  • i see quote_id in quote_payment table i use quote id in browser url as you suggest but nothing is showing. Just this msg is showing <message>Consumer is not authorized to access %resources</message> – Ramkishan Suthar Sep 29 '16 at 6:57
  • give me compete url what you are using so i will tell you ? – Brad Hodge Sep 29 '16 at 7:00
  •…. where 261 is quote id from quote_payment table – Ramkishan Suthar Sep 29 '16 at 7:03
  • Sorry its on quote Table :filed name : "entity_id" – Brad Hodge Sep 29 '16 at 8:38

This worked for me.

public function __construct(
    \Magento\Checkout\Model\Cart $cart,
) {
    $this->_cart = $cart;

function testFunction(){
    $cartID = $this->_cart->getQuote()->getId();

You can use following code to get the cart_id

$cart = $objectManager->get('\Magento\Checkout\Model\Cart'); 
  • 4
    You should not use the objectManager. – vitoriodachef Apr 25 '18 at 10:45
  • @vitoriodachef Why? Is it a flaw – VishalParkash Nov 10 '20 at 7:50
  • 1
    @VishalParkash it prevents all the benefits of dependency injection thus making the code more rigid and sometimes impossible to cover using unit tests. I urge you to search for the benefits of DI on your own, it will make more sense once you take a look at it. – vitoriodachef Nov 10 '20 at 8:00

If you come here for a bigger cart_id(something like 1WxKm8WUm3uFKXLlHXezew5WREfVRPAn, not a simple number). Then that is masked_id. You can find this value in table quote_id_mask.

Also, Magento\Quote\Model\QuoteIdMaskFactory can be used to get masked_id.

public function execute()
    $data = $this->_jsonHelper->jsonDecode($this->getRequest()->getContent());
    $maskedQuoteId = $data['quoteId'];
    $quoteIdMask = $this->quoteIdMaskFactory->create()->load($maskedQuoteId, 'masked_id');
    $quoteId = $quoteIdMask->getQuoteId();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.