hendt / ebay-api

eBay Node API in TypeScript for Node and Browser with RESTful and Traditional APIs. This library aims to implement all available eBay apis.
https://hendt.gitbook.io/ebay-api
MIT License
149 stars 40 forks source link

get listing policies of sku in an inventory items #159

Open taaha1234 opened 9 months ago

taaha1234 commented 9 months ago

app.get('/offersPolicies', async function (req, res) { try {

const token = await getTokenInformation(1);

if(!token) {
  return res.sendStatus(403);
}
eBay.OAuth2.setCredentials(token);

eBay.OAuth2.on('refreshAuthToken', (refreshedToken) => {
  req.session.token = refreshedToken;
});

const viewItemSku = req.query.sku;
console.log('sku:', viewItemSku)

// const isValidSku = /^[a-zA-Z0-9]{1,50}$/.test(viewItemSku); // if (!isValidSku) { // return res.status(400).send({ error: 'Invalid SKU format' }); // }

const allOffers = await eBay.sell.inventory.getOffers(`${viewItemSku}`);
console.log(allOffers)

// res.json(allOffers);
res.send(allOffers)

} catch (error) { console.error('Error:', error); res.status(400).send({ error: error.message }); } }); when i hit this api on postman ("/offersPolicies?sku=MG39-E29") the response was bad request and the error in message is show is ("{ "error": "This is an invalid value for a SKU. Only alphanumeric characters can be used for SKUs, and their length must not exceed 50 characters" }") please guide me

dantio commented 8 months ago

Use the getInventoryItems method to retrieve SKU values.

Can you check your SKUs with the getInventoryItems() call?

const items = await eBay.sell.inventory.getInventoryItems();
console.log(items);