I’m getting a 400 error when making a request to the Amazon Selling Partner API. I already tried it without the “https://”. I am only getting this error when trying any other endpoint than orders/v0/orders.
const axios = require('axios');
const { locale } = require('moment');
require('dotenv').config({ path: './api.env' });
async function apiCall() {
try {
// Step 1: Get the LWA access token
const tokenResponse = await axios.post(
'https://api.amazon.com/auth/o2/token',
new URLSearchParams({
grant_type: 'refresh_token',
refresh_token: process.env.REFRESH_TOKEN,
client_id: process.env.CLIENT_ID,
client_secret: process.env.SECRET_KEY,
})
);
const accessToken = tokenResponse.data.access_token;
console.log('Access token:', accessToken);
// Step 2: Set the SP API endpoint and marketplace ID
const endpoint = 'https://sellingpartnerapi-eu.amazon.com';
const marketplaceId = 'A1PA6795UKMFR9';
// Step 3: Prepare the request parameters
const requestParams = {
asins: ['B00V5DG6IQ' , 'B00551Q3CS'],
MarketplaceId: marketplaceId,
itemType: 'ASIN',
};
// Step 4: Make the API call to get orders
const ordersResponse = await axios.get(`${endpoint}/products/pricing/v0/price`, {
params: requestParams,
headers: {
'x-amz-access-token': accessToken,
},
});
// Step 5: Return or process the JSON response
console.log(JSON.stringify(ordersResponse.data, null, 2));
return ordersResponse.data;
} catch (error) {
console.error('Error making API call:', error);
}
}
module.exports = apiCall;