Bagisto Forum

    Bagisto

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

    I need a tutorial on "Bagisto API+Headless eCommerce" for "Bagisto 2.0".

    Installing Bagisto
    2
    8
    1856
    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.
    • T
      tmss last edited by

      I would like to use "Bagisto API+Headless eCommerce" with "Bagisto 2.0" based on the following document.

      I've been researching for 2 days and can't seem to find a good starting point for implementation.
      Is there a tutorial for implementing "Bagisto API+Headless eCommerce" in 2.0?

      I'm thinking "Headless eCommerce=GraphQL", but I'd like to start with Bagisto API alone and use "GraphQL" if it seems necessary.
      (I don't know the advantages of "GraphQL" yet...)

      Headless eCommerce
      https://bagisto.com/en/headless-ecommerce/
      Bagisto API
      https://devdocs.bagisto.com/2.x/api/

      1 Reply Last reply Reply Quote 0
      • Rishabh-Webkul
        Rishabh-Webkul last edited by

        Hello @tmss

        Greetings of the day..!!

        If you need to install the Bagisto Headless Ecommerce (GraphQL API) this is the official repository here download or clone the package and use it accordingly.

        GitHub Link - https://github.com/bagisto/headless-ecommerce

        and if you need the endpoints you can copy the below file and import it inside your Postman.

        https://github.com/bagisto/headless-ecommerce/blob/main/Postman_APIs/Collections/Headless-API.postman_collection.json

        NOTE - Kindly check the below instructions in the ReadMe file for setup.

        Thanks & Regards..!!

        T 1 Reply Last reply Reply Quote 0
        • T
          tmss @Rishabh-Webkul last edited by tmss

          @Rishabh-Webkul

          Thank you for your answer!
          It is helpful as I need to solve this issue personally.

          In the meantime, I installed everything and checked the operation according to the following documents.

          1. graphQL
            https://github.com/bagisto/headless-ecommerce

          2. Bagisto Rest API
            https://devdocs.bagisto.com/2.x/api/getting-started-with-the-api.html#explore-rest-api-demo

          I tried to install each of them according to the official version, but they still don't seem to work properly.
          I get a 500 error on the "GraphQL" query confirmation screen.

          Now, I want to know if the "Bagisto Rest API" is working well, so I register a new user and run the following API command to issue a token at login in "Laravel Sanctam".

          curl -X 'POST' \
            'http://localhost/api/v1/customer/login' \
            -H 'accept: application/json' \
            -H 'Content-Type: application/json' \
            -H 'X-CSRF-TOKEN: qepNwaFlVukUhjiImoggYwABgbiLnHqQ6BRhjqnv' \
            -d '{
              "email": "shop@example.com",
              "password": "demo123",
              "device_name": "android"
            }' 
          

          The result is a 500 error, with the following error in the Laravel log

          local.ERROR: Webkul\Checkout\Cart::mergeCart(): Argument #1 ($customer) must be of type Webkul\Customer\Contracts\Customer, string given,.
          ~
          

          Logging in from a browser works fine.
          Disabling CSRF in "bagisto/app/Http/Middleware/VerifyCsrfToken.php" does not resolve the 500 error.

              protected $except = [
                  //URL to disable CSRF
                  'api/*',.
              ];
          

          Can you resolve this?
          Thank you in advance for your time and help with the solution.

          I would like to check and investigate the "GraphQL" after this is successfully done.

          T 1 Reply Last reply Reply Quote 0
          • T
            tmss @tmss last edited by


            Postscript.
            5/22 17:45 JST

            bagisto/vendor/bagisto/rest-api/src/Http/Controllers/V1/Shop/Customer/AuthController.php
            

            was commented out and I was able to log in.

            Event::dispatch('customer.after.login', $request->get('email'));
            

            I have not yet figured out where this function is located.

            1 Reply Last reply Reply Quote 0
            • Rishabh-Webkul
              Rishabh-Webkul last edited by

              Hello @tmss

              Greetings of the day..!!

              Kindly check the below link in this blog there is an installation as well as how to show endpoints for GraphQL and Rest API.

              Link - https://bagisto.com/en/bagisto-api/

              Thanks & Regards..!!

              T 1 Reply Last reply Reply Quote 0
              • T
                tmss @Rishabh-Webkul last edited by tmss

                @Rishabh-Webkul

                Thank you for the installation instructions.
                This has definitely been done and reflected.

                I am sorry, but I would like to make sure that the Bagsit REST API is working properly first before I do "GlaphQL".

                Right now I am getting an error with the API login.


                ↓I think the REST API is working because this API works.

                curl -X GET "http://localhost/api/v1/core-configs?_config[]=general.general.locale_options.weight_unit" \
                -H 'Accept: application/json' \
                -H 'Content-Type: application/json'
                

                ↓ LOGIN API with this error.

                curl -X 'POST' \
                  'http://localhost/api/v1/customer/login' \
                  -H 'accept: application/json' \
                  -H 'Content-Type: application/json' \
                  -d '{
                    "email": "shop@example.com",.
                    "password": "demo123", "device_name": "and
                    "device_name": "android"
                  }'
                
                local.ERROR: Webkul\Checkout\Cart::mergeCart(): Argument #1 ($customer) must be of type Webkul\Customer\Contracts\Customer, string given, called in /var/www/html/bagisto/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 355 {"exception":"[object] (TypeError(code: 0): Webkul\\Checkout\\Cart::mergeCart(): Argument #1 ($customer) must be of type Webkul\\Customer\\Contracts\\Customer, string given, called in /var/www/html/bagisto/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 355 at /var/www/html/bagisto/packages/Webkul/Checkout/src/Cart.php:197)
                

                ↓ If you comment out this code, you can log in with the API as well.

                bagisto/vendor/bagisto/rest-api/src/Http/Controllers/V1/Shop/Customer/AuthController.php
                
                Event::dispatch('customer.after.login', $request->get('email'));
                
                • I haven't been able to track down where the Event::dispatch is located.

                The function causing the error seems to be here.

                packages/Webkul/Checkout/src/Cart.php
                
                    /**
                     * This method handles when guest has some of cart products and then logs in.
                     */
                    public function mergeCart(CustomerContract $customer): void
                    {~}
                
                

                ※Function passes when either browser login or API login is used.

                This seems to be the way it works, though,
                Is this normal behavior?

                Sorry if I am wrong.

                It is an absolute rule to develop packages without touching "Bagisto itself" or "Webkul", so please help me out.

                1 Reply Last reply Reply Quote 0
                • Rishabh-Webkul
                  Rishabh-Webkul last edited by

                  Hello @tmss

                  Greetings of the day..!!

                  Kindly make sure and confirm your Bagisto and API versions are compatible with each other.

                  If you are using Bagisto 2.0 then install the API version according to your version.

                  Thanks & Regards..!!

                  T 1 Reply Last reply Reply Quote 0
                  • T
                    tmss @Rishabh-Webkul last edited by

                    @Rishabh-Webkul

                    Thank you for your confirmation.
                    I installed with Bagisrto ver2 on this page

                    https://devdocs.bagisto.com/2.x/api/getting-started-with-the-api.html#explore-rest-api-demo

                    The installation commands are as follows
                    composer require bagisto/rest-api dev-master

                    https://bagisto.com/en/bagisto-api/
                    This is also installed with "dev-master" as well.

                    If you look here, you will find v2.0.0.
                    https://github.com/bagisto/rest-api

                    composer require bagisto/rest-api v2.0.0

                    is this correct?
                    The description is different from the manual, is it ok?
                    Should I not use dev-master?

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post