SDKs & Libraries
Client libraries and development tools for API integration.
SDKs & Libraries
Official and community-maintained SDKs and libraries for easy API integration.
Official SDKs
JavaScript/TypeScript SDK
Install the JavaScript SDK for Node.js and browser environments:
npm install @smart-shelf/sdk
Basic Usage
import { SmartShelfClient } from '@smart-shelf/sdk'
const client = new SmartShelfClient({
apiKey: 'your_api_key',
baseUrl: 'https://your-domain.com/api'
})
// Get products
const products = await client.products.list({
limit: 20,
category: 'electronics'
})
// Create product
const newProduct = await client.products.create({
name: 'New Widget',
sku: 'NW-001',
price: 29.99
})
// Update inventory
await client.inventory.recordMovement({
productId: 'prod_123',
warehouseId: 'wh_789',
movementType: 'in',
quantity: 50
})
Configuration Options
const client = new SmartShelfClient({
apiKey: 'your_api_key',
baseUrl: 'https://your-domain.com/api',
timeout: 30000,
retries: 3,
rateLimitRetry: true,
debug: false
})
Error Handling
try {
const product = await client.products.get('prod_123')
} catch (error) {
if (error.code === 'RESOURCE_NOT_FOUND') {
console.log('Product not found')
} else if (error.code === 'RATE_LIMIT_EXCEEDED') {
console.log('Rate limit exceeded, retry after:', error.retryAfter)
} else {
console.error('API Error:', error.message)
}
}
Pagination
// Auto-pagination
const allProducts = []
for await (const product of client.products.listAll()) {
allProducts.push(product)
}
// Manual pagination
let page = 1
let hasMore = true
while (hasMore) {
const response = await client.products.list({ page, limit: 100 })
allProducts.push(...response.data)
hasMore = response.meta.hasMore
page++
}
Webhooks
// Verify webhook signatures
const isValid = client.webhooks.verifySignature(
payload,
signature,
webhookSecret
)
// Parse webhook payload
const event = client.webhooks.parseEvent(payload)
console.log('Event type:', event.type)
console.log('Event data:', event.data)
Python SDK
Install the Python SDK:
pip install smart-shelf-python
Basic Usage
from smart_shelf import SmartShelfClient
client = SmartShelfClient(
api_key='your_api_key',
base_url='https://your-domain.com/api'
)
# Get products
products = client.products.list(limit=20, category='electronics')
# Create product
new_product = client.products.create({
'name': 'New Widget',
'sku': 'NW-001',
'price': 29.99
})
# Update inventory
client.inventory.record_movement({
'product_id': 'prod_123',
'warehouse_id': 'wh_789',
'movement_type': 'in',
'quantity': 50
})
Configuration Options
client = SmartShelfClient(
api_key='your_api_key',
base_url='https://your-domain.com/api',
timeout=30,
retries=3,
rate_limit_retry=True,
debug=False
)
Error Handling
from smart_shelf.exceptions import (
SmartShelfError,
ResourceNotFoundError,
RateLimitError
)
try:
product = client.products.get('prod_123')
except ResourceNotFoundError:
print('Product not found')
except RateLimitError as e:
print(f'Rate limit exceeded, retry after: {e.retry_after}')
except SmartShelfError as e:
print(f'API Error: {e.message}')
Pagination
# Auto-pagination
all_products = []
for product in client.products.list_all():
all_products.append(product)
# Manual pagination
page = 1
has_more = True
while has_more:
response = client.products.list(page=page, limit=100)
all_products.extend(response.data)
has_more = response.meta.has_more
page += 1
Webhooks
# Verify webhook signatures
is_valid = client.webhooks.verify_signature(
payload,
signature,
webhook_secret
)
# Parse webhook payload
event = client.webhooks.parse_event(payload)
print(f'Event type: {event.type}')
print(f'Event data: {event.data}')
cURL Examples
Authentication
# Set your API key
export API_KEY="your_jwt_token"
export BASE_URL="https://your-domain.com/api"
Get Products
curl -X GET \
"$BASE_URL/products?limit=20" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json"
Create Product
curl -X POST \
"$BASE_URL/products" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "New Widget",
"sku": "NW-001",
"category_id": "cat_456",
"cost_price": 25.00,
"selling_price": 49.99
}'
Record Inventory Movement
curl -X POST \
"$BASE_URL/inventory/movements" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"product_id": "prod_123",
"warehouse_id": "wh_789",
"movement_type": "in",
"quantity": 50,
"notes": "Received from supplier"
}'
Get Analytics Dashboard
curl -X GET \
"$BASE_URL/analytics/dashboard?period=30d" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json"
Community SDKs
PHP SDK
composer require smartshelf/php-sdk
<?php
use SmartShelf\Client;
$client = new Client([
'api_key' => 'your_api_key',
'base_url' => 'https://your-domain.com/api'
]);
$products = $client->products()->list(['limit' => 20]);
?>
Ruby SDK
gem install smart_shelf
require 'smart_shelf'
client = SmartShelf::Client.new(
api_key: 'your_api_key',
base_url: 'https://your-domain.com/api'
)
products = client.products.list(limit: 20)
Go SDK
go get github.com/smartshelf/go-sdk
package main
import (
"github.com/smartshelf/go-sdk"
)
func main() {
client := smartshelf.NewClient("your_api_key", "https://your-domain.com/api")
products, err := client.Products.List(&smartshelf.ProductListOptions{
Limit: 20,
})
if err != nil {
panic(err)
}
}
Integration Examples
Webhook Handler (Node.js/Express)
const express = require('express')
const { SmartShelfClient } = require('@smart-shelf/sdk')
const app = express()
const client = new SmartShelfClient({ apiKey: 'your_api_key' })
app.post('/webhooks/smartshelf', express.raw({ type: 'application/json' }), (req, res) => {
const signature = req.headers['x-signature']
const payload = req.body
// Verify webhook signature
if (!client.webhooks.verifySignature(payload, signature, 'webhook_secret')) {
return res.status(401).send('Invalid signature')
}
const event = client.webhooks.parseEvent(payload)
switch (event.type) {
case 'inventory.low_stock':
console.log('Low stock alert:', event.data.object)
// Handle low stock notification
break
case 'order.created':
console.log('New order:', event.data.object)
// Process new order
break
default:
console.log('Unhandled event type:', event.type)
}
res.status(200).send('OK')
})
app.listen(3000)
React Hook
import { useState, useEffect } from 'react'
import { SmartShelfClient } from '@smart-shelf/sdk'
const client = new SmartShelfClient({ apiKey: 'your_api_key' })
function useProducts(filters = {}) {
const [products, setProducts] = useState([])
const [loading, setLoading] = useState(true)
const [error, setError] = useState(null)
useEffect(() => {
async function fetchProducts() {
try {
setLoading(true)
const response = await client.products.list(filters)
setProducts(response.data)
} catch (err) {
setError(err)
} finally {
setLoading(false)
}
}
fetchProducts()
}, [filters])
return { products, loading, error }
}
function ProductList() {
const { products, loading, error } = useProducts({ limit: 50 })
if (loading) return <div>Loading...</div>
if (error) return <div>Error: {error.message}</div>
return (
<ul>
{products.map(product => (
<li key={product.id}>{product.name} - ${product.price}</li>
))}
</ul>
)
}
CLI Tool
# Install CLI tool
npm install -g @smart-shelf/cli
# Configure
smart-shelf config set api-key your_api_key
smart-shelf config set base-url https://your-domain.com/api
# Use CLI commands
smart-shelf products list --limit 20
smart-shelf inventory check --warehouse main
smart-shelf orders create --customer cust_123 --items prod_456:2