TypeScript and JavaScript SDK
Last updated · Changelog · OpenAPI spec · Markdown
Our official TypeScript/JavaScript SDK provides a convenient way to interact with the ShopSavvy Data API from Node.js and browser environments.
Installation
npm install @shopsavvy/sdk
# or
yarn add @shopsavvy/data-api
# or
bun add @shopsavvy/data-apiBasic Usage
import { createShopSavvyClient } from '@shopsavvy/data-api'
// Initialize the client
const api = createShopSavvyClient({
apiKey: 'ss_live_your_api_key_here'
})
// Look up a product by barcode
const product = await api.getProductDetails('012345678901')
console.log(product.data.name)
// Get current prices from all retailers
const offers = await api.getCurrentOffers('012345678901')
offers.data.forEach(offer => {
console.log(`${offer.retailer}: $${offer.price}`)
})
// Get price history
const history = await api.getPriceHistory(
'012345678901',
'2024-01-01',
'2024-01-31'
)Features
- Full TypeScript support with comprehensive type definitions
- Modern async/await API
- Automatic error handling and retry logic
- Support for both Node.js and browser environments
- Built-in request/response validation
- Comprehensive documentation and examples
Error Handling
try {
const product = await api.getProductDetails('invalid-identifier')
} catch (error) {
if (error.message.includes('Product not found')) {
console.log('Product does not exist')
} else if (error.message.includes('Invalid API key')) {
console.log('Check your API key')
} else {
console.log('Unexpected error:', error.message)
}
}Was this page helpful?