Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

muazzamazaz's avatar

Getting invalid input error at amazon selling partner api

Route: Route::get('/amazon-products', [AmazonSPApiController::class, 'getProducts']);

and controller class:

use App\Services\AmazonSPApiService;
use Illuminate\Http\Request;

class AmazonSPApiController extends Controller
{
    protected $amazonSPApiService;

    public function __construct(AmazonSPApiService $amazonSPApiService)
    {
        $this->amazonSPApiService = $amazonSPApiService;
    }

    public function getProducts()
    {
        $products = $this->amazonSPApiService->getProducts();

        if ($products) {
            return response()->json(['data' => $products]);
        } else {
            return response()->json(['error' => 'Unable to fetch products'], 500);
        }
    }

this cataglog items api returns Invalid Input error when I call above route where controller class is using AmazonSPApiService service

0 likes
2 replies
tuncdogu55's avatar

I couldn't find the field asin in the Catalog Items API documentation at this link:

https://developer-docs.amazon.com/sp-api/docs/catalog-items-api-v2022-04-01-reference

If this is the correct link, it seems that asin might not be a part of the request parameters. Since asin is a unique identifier for a product, if you want to retrieve information for a specific product, your request might need to look like this:

public function getOneProduct($productAsin)
{
    $endpoint = '/catalog/v0/items/'.$productAsin; // Example endpoint for catalog
    $params = [
        'marketplaceId' => 'ATVPDKIKX0DER', // Example marketplace ID
    ];
    return $this->makeApiRequest($endpoint, 'GET', $params);
}

Could you try making the request in this format? This method should allow you to retrieve information for a single product using its ASIN.

And for your all product :

 public function getProducts()
    {
        $endpoint = '/catalog/v0/items'; // Example endpoint for catalog
        $params = [
            'marketplaceId' => 'ATVPDKIKX0DER', // Example marketplace ID
        ];
        return $this->makeApiRequest($endpoint, 'GET', $params);
    }

I hope this will be helpfull for your problem.

martinbean's avatar

@muazzamazaz You shouldn’t be using the env helper in your code. You should be mapping environment variables to configuration values:

// config/services.php
return [
    'amazon' => [
        'selling_partner' => [
            'key' => env('AMAZON_SP_API_ACCESS_KEY_ID'),
            'secret' => env('AMAZON_SP_API_SECRET_ACCESS_KEY'),
            'refresh_token' => env('AMAZON_SP_API_REFRESH_TOKEN'),
            'client_id' => env('AMAZON_SP_API_CLIENT_ID'),
            'client_secret' => env('AMAZON_SP_API_CLIENT_SECRET'),
            'seller_id' => env('AMAZON_SP_API_SELLER_ID'),
        ],
    ],
];

You could then actually bind a fully-configured instance of your service class to the service container, and inject that into your controller instead:

public function register(): void
{
    $this->app->singleton(AmazonSellingPartnerService::class, function () {
        return new AmazonSellingPartnerService(
          // Actually pass configuration values instead of
          // grabbing them in your constructor
        );
    });
}
class FooController extends Controller
{
    protected AmazonSellingPartnerService $service;

    public function __construct(AmazonSellingPartnerService $service)
    {
        $this->service = $service;
    }
}

Please or to participate in this conversation.