Bagisto Forum

    Bagisto

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

    Product API behaving strangely - cannot fetch data for a single product

    General Discussion
    3
    9
    3062
    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.
    • K
      KiwiNFLFan last edited by

      I noticed that the product API on my Bagisto site was behaving very strangely when it comes to fetching single items. I can fetch a paginated list of products at api/products, but when I try to fetch data for a single product, it behaves very strangely.

      Attempting to fetch a single product with the SKU, URL key or name as a parameter returns an empty set, as does attempting to fetch all featured or new products.
      postman1.png

      Fetching a product by ID simply returns the same paginated list of all products as calling api/products.

      I have no idea what is going on here. Is something misconfigured on the server or with the database?

      1 Reply Last reply Reply Quote 0
      • devansh-webkul
        devansh-webkul last edited by

        Hi @KiwiNFLFan,

        • Please check the documentation,
          https://devdocs.bagisto.com/1.x/api/products.html#get-products-with-query-parameters

        • I have checked all your params and its working fine,

          Screenshot from 2021-05-12 09-25-25.png

        • And the second thing, its url_key not url-key,

          url.png

        1 Reply Last reply Reply Quote 0
        • K
          KiwiNFLFan last edited by

          Hi devansh,

          Thanks. I checked the documentation for product requests with query parameters and tried a request for each of the parameters. limit and page work as expected, as does category_id (returns all the products in a given category).

          However, the others (including the correct spelling for url_key) all return an empty data array, even featured=0 and new=0. I am certain there are products in my database that meet those criteria.

          Is this a database issue, or what? Any ideas?

          You can try a request here: https://ncodebkk.ga/api/products?url_key=wacky-rugged-print-t-shirt . It should return an empty array, despite the fact that the product clearly exists (as can be seen from this request):
          postmanprod.png

          1 Reply Last reply Reply Quote 0
          • devansh-webkul
            devansh-webkul last edited by

            Have you done any changes because in my instance it's working fine?

            K 1 Reply Last reply Reply Quote 0
            • K
              KiwiNFLFan @devansh-webkul last edited by

              @devansh-webkul Yes, I made one small change - I added a single line of code to packages\Webkul\API\Http\Resources\Catalog\Product.php. Right below line 65 (in_stock), I added the following line, which worked perfectly previously:

              'stock_quantity' => $product->totalQuantity(),

              This was at the request of my clients, who would like the mobile app I am building to display the current stock quantity of each product.

              Could this one line of code really have caused this? I tested it after adding the line, and it worked fine. It's only been this past week when the API has been playing up.

              1 Reply Last reply Reply Quote 0
              • K
                KiwiNFLFan last edited by

                UPDATE:

                I did a local install of Bagisto on my local PC (Linux Mint), imported the dumped database from my server to my local MariaDB instance, imported the images from the server and....

                Exactly the same problem!

                I made no modifications to the Bagisto code this time, so this issue has to be something to do with the data itself and the way it is stored.

                Any ideas what is going on here?

                1 Reply Last reply Reply Quote 0
                • K
                  KiwiNFLFan last edited by

                  I fixed the problem.

                  I had two levels of categories: Women/Men, and then subcategories under each of those (in addition to Root). I had listed the product in both the appropriate sub-category (e.g. T-shirts) as well as the parent category (e.g. Women).

                  After I unticked either Women or Men in the dashboard, meaning that each product has only one category, i.e. the most detailed sub-category, the product API returns the correct data.

                  1 Reply Last reply Reply Quote 0
                  • S
                    sonalichopra712 last edited by

                    I am facing EXACTLY the same issue but couldn't able to solve it

                    1 Reply Last reply Reply Quote 0
                    • devansh-webkul
                      devansh-webkul last edited by

                      Hi @sonalichopra712,

                      Please check the @KiwiNFLFan answer.

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