• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Register
  • Login
Bagisto Forum

Bagisto

  • Register
  • Login
  • Search
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups

Guest cart issue using "bagisto/rest-api": "^2.1"

Knowledge Base
3
6
483
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M
    marshalbagisto last edited by 11 Oct 2024, 04:08

    Hello Bagisto Team,

    I am using rest-api version 2.1. I am not able to add the product to the cart.

    Endpoint: {{baseUrl}}/api/v1/customer/cart/add/476
    
    
    Request: {
      "is_buy_now": 0,
      "product_id": 476,
      "quantity": 1
    }
    
    Response: {
        "message": "Unauthenticated."
    }
    

    Can you please help me with this?

    Thank you

    A 1 Reply Last reply 11 Oct 2024, 04:21 Reply Quote 0
    • A
      amit-webkul @marshalbagisto last edited by 11 Oct 2024, 04:21

      Hello @marshalbagisto ,

      As I can see in your request and response data, it clearly shows you are not authenticated by the user. Please login first with any user; after that, try to hit Add to Cart API. It will work for only logged-in customers.

      Please try doing this, and if you get an issue, let us know.

      M 1 Reply Last reply 12 Oct 2024, 13:07 Reply Quote 0
      • M
        marshalbagisto @amit-webkul last edited by 12 Oct 2024, 13:07

        @amit-webkul Hi Amit!

        Yes, after user login it is working already. The issue is. I want to prompt the user to log-in while checkout and do them regular cart operations without log-in. Do you think this is possible? If yes, can you please guide me?

        Thank you

        A 1 Reply Last reply 14 Oct 2024, 04:35 Reply Quote 0
        • A
          amit-webkul @marshalbagisto last edited by 14 Oct 2024, 04:35

          @marshalbagisto

          If you want to add user login to the checkout section, and before that, the cart should work for a guest also, so you need to override the cart and checkout API and customize as per your need.

          Like first, you need to provide access to the cart for guest users. After doing this, you will need to manage the checkout API as well.

          1 Reply Last reply Reply Quote 0
          • P
            Peppek1993 last edited by 14 Oct 2024, 18:13

            The answers from @amit-webkul are not what you are looking for probably.

            In rest-api we don't get any routes for guests, everything is based on JWT for already logged in users.

            If you want to do operations for guests you need to use XSRF tokens as authentication.

            in order to do that, you need to call api/customer/cart GET (not api/v1/customer/cart), this will SET xsrf-token cookie for your domain.

            after that, on adding to cart and every other operation you need to include that xsrf token

            credentials: 'include',
            'Cookie': `XSRF-TOKEN=${useCookie('XSRF-TOKEN')}; oronegro_session=${useCookie('oronegro_session')}`,
            'X-XSRF-TOKEN': useCookie('XSRF-TOKEN')
            
            M 1 Reply Last reply 15 Oct 2024, 02:40 Reply Quote 0
            • M
              marshalbagisto @Peppek1993 last edited by 15 Oct 2024, 02:40

              @Peppek1993 Thank you. I'll try and update here the progress.

              1 Reply Last reply Reply Quote 0
              4 out of 6
              • First post
                4/6
                Last post