keithbrink / amazon-mws-laravel

A Laravel library for Amazon's MWS web services, supporting Laravel 5-8+
Apache License 2.0
27 stars 23 forks source link

400 Bad Request - Required parameter ASIN not found for GetProductCategoriesForASIN #52

Closed hfuccillo closed 2 years ago

hfuccillo commented 3 years ago

I need to fetch product categories by using this endpoint: https://docs.developer.amazonservices.com/en_UK/products/Products_GetProductCategoriesForASIN.html

One of the requested parameters is ASIN but using the method setASINs this parameter is assigned ASINList.ASIN.1 instead of ASIN. As far as I checked, the rest of the endpoints needs the ASINList.ASIN.1 parameter and not the ASIN one. But somehow for this endpoint only ASIN parameter is needed.

public function setASINs($s)
    {
        if (is_string($s)) {
            $this->resetSKUs();
            $this->resetASINs();
            $this->options['ASINList.ASIN.1'] = $s;
        } else {
            if (is_array($s)) {
                $this->resetSKUs();
                $this->resetASINs();
                $i = 1;
                foreach ($s as $x) {
                    $this->options['ASINList.ASIN.'.$i] = $x;
                    $i++;
                }
            } else {
                return false;
            }
        }
    }

If I just set the parameter ASIN $this->options['ASIN'] = $s; it works like a charm:

public function setASINs($s)
    {
        if (is_string($s)) {
            $this->resetSKUs();
            $this->resetASINs();
            $this->options['ASINList.ASIN.1'] = $s;
            $this->options['ASIN'] = $s;
        } else {
            if (is_array($s)) {
                $this->resetSKUs();
                $this->resetASINs();
                $i = 1;
                foreach ($s as $x) {
                    $this->options['ASINList.ASIN.'.$i] = $x;
                    $i++;
                }
            } else {
                return false;
            }
        }
    }

Is it possible to fix it? This is clearly an exception and can be managed in two ways, duplicating the parameter and sending it in every request or catch the request asking for categories and only set the proper one.

keithbrink commented 2 years ago

Fixed in 8.0.6, thanks!

spire-mike commented 1 year ago

Hi @keithbrink, are you sure @hfuccillo's issue is fixed? I am having the same issue using 8.1.0, and the commit referenced above (https://github.com/keithbrink/amazon-mws-laravel/commit/279e06053de3239e64cec38dfe2ba9bc9b67d168) does not contain code that fixes the issue. You need to set a single SellerSKU or ASIN option for fetching product categories.

keithbrink commented 1 year ago

@spire-mike I am no longer maintaining this package, I've moved to the new API. Feel free to send a PR in.

spire-mike commented 1 year ago

@keithbrink thanks. I see it actually is fixed for the case of ASIN, but not SellerSKU. It should be a one-line fix. I'll submit a PR. Thank you!

spire-mike commented 1 year ago

Here you go @keithbrink https://github.com/keithbrink/amazon-mws-laravel/pull/64