Getting invalid input error at amazon selling partner api

Countries

Read only
Australia
Belgium
Brazil
Canada
Egypt
France
Germany
India
Italy
Japan
Mexico
Netherlands
Poland
Saudi Arabia
Singapore
Spain
Sweden
Turkey
United Arab Emirates
United Kingdom
United States
United States
imgSign in
Participate for your chance to win $100 Amazon Gift Card HERE.Spring Forum Sweepstakes
user profile
Seller_Aow55Op0eSrnJ

Getting invalid input error at amazon selling partner api

```

<?php

namespace App\Services;

use Illuminate\Support\Facades\Http;

use Illuminate\Support\Facades\Log;

use Carbon\Carbon;

class AmazonSPApiService

{

private $accessKeyId;

private $secretAccessKey;

private $refreshToken;

private $clientId;

private $clientSecret;

private $sellerId;

public function __construct()

{

$this->accessKeyId = env('AMAZON_SP_API_ACCESS_KEY_ID');

$this->secretAccessKey = env('AMAZON_SP_API_SECRET_ACCESS_KEY');

$this->refreshToken = env('AMAZON_SP_API_REFRESH_TOKEN');

$this->clientId = env('AMAZON_SP_API_CLIENT_ID');

$this->clientSecret = env('AMAZON_SP_API_CLIENT_SECRET');

$this->sellerId = env('AMAZON_SP_API_SELLER_ID');

}

private function getAccessToken()

{

$url = 'https://api.amazon.com/auth/o2/token';

$response = Http::asForm()->post($url, [

'grant_type' => 'refresh_token',

'refresh_token' => $this->refreshToken,

'client_id' => $this->clientId,

'client_secret' => $this->clientSecret,

]);

$data = $response->json();

return $data['access_token'];

}

private function makeApiRequest($endpoint, $method = 'GET', $params = [])

{

$token = $this->getAccessToken();

$url = "https://sellingpartnerapi-na.amazon.com$endpoint";

// dd($token);

try {

$response = Http::withHeaders([

'Authorization' => "Bearer $token",

'x-amz-access-token' => $token,

'x-amz-date' => Carbon::now()->format('Ymd\THis\Z'),

])->$method($url, $params);

dd($response->json());

return $response->json();

} catch (\Exception $e) {

Log::error('Error making SP API request: ' . $e->getMessage());

return null;

}

}

public function getProducts()

{

$endpoint = '/catalog/v0/items'; // Example endpoint for catalog

$params = [

'asin' => 'B07JGTVTWN', // Example ASIN, replace with your own

'marketplaceId' => 'ATVPDKIKX0DER', // Example marketplace ID

];

return $this->makeApiRequest($endpoint, 'GET', $params);

}

// Add more methods to interact with other SP API endpoints

}

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

laravelamazon-selling-partner-api

23 views
2 replies
Tags:Seller Central
00
Reply
2 replies
user profile
Connor_Amazon

Hi @Seller_Aow55Op0eSrnJ

Connor from Amazon here, thanks for your question.

Please reach out to seller support for technical questions. We are not able to see why you get an API error.

-Connor

00
Follow this discussion to be notified of new activity

Similar Discussions

user profile
Seller_fbuyER5LDIjBF
user profile
Seller_WDq0p9I7tZZGy
user profile
Seller_Z7WGnL1NjWkYQ