SDK Reference
@proveanything/smartlinks
Namespaces
order
Functions for order operations
create
Create a new order with items. typescript const order = await order.create('coll_123', { orderRef: 'ORD-12345', customerId: 'CUST-789', items: [ { itemType: 'tag', itemId: 'TAG001' }, { itemType: 'tag', itemId: 'TAG002' }, { itemType: 'serial', itemId: 'SN12345' } ], status: 'pending', metadata: { shipmentId: 'SHIP-789', destination: 'Warehouse B' } })
create(collectionId: string,
data: ) → Promise<CreateOrderResponse>get
Get a single order by ID. typescript // Get order without items (faster) const order = await order.get('coll_123', 'order_abc123') console.log(`Order has ${order.itemCount} items`) // Get order with items const orderWithItems = await order.get('coll_123', 'order_abc123', { includeItems: true }) console.log(orderWithItems.items) // Items array available
get(collectionId: string,
orderId: string,
params?: ) → Promise<GetOrderResponse>update
Update order status or metadata. Items are managed separately via addItems/removeItems. typescript const updated = await order.update('coll_123', 'order_abc123', { status: 'shipped', metadata: { trackingNumber: '1Z999AA10123456784', shippedAt: '2026-02-02T14:30:00Z' } })
update(collectionId: string,
orderId: string,
data: ) → Promise<UpdateOrderResponse>remove
Delete an order and all its items (cascade delete). typescript await order.remove('coll_123', 'order_abc123')
remove(collectionId: string,
orderId: string) → Promise<>list
List orders for a collection with optional filters and pagination. Orders are returned in descending order by createdAt (newest first). typescript // List all orders (without items for better performance) const all = await order.list('coll_123') // List with filters const pending = await order.list('coll_123', { status: 'pending', limit: 50, offset: 0 }) // Filter by customer with items const customerOrders = await order.list('coll_123', { customerId: 'CUST-789', includeItems: true })
list(collectionId: string,
params?: ) → Promise<>getItems
Get items from an order with pagination support. Use this for orders with many items instead of includeItems. typescript // Get first page of items const page1 = await order.getItems('coll_123', 'order_abc123', { limit: 100, offset: 0 }) // Get next page const page2 = await order.getItems('coll_123', 'order_abc123', { limit: 100, offset: 100 })
getItems(collectionId: string,
orderId: string,
params?: ) → Promise<>addItems
Add additional items to an existing order. typescript const updated = await order.addItems('coll_123', 'order_abc123', { items: [ { itemType: 'tag', itemId: 'TAG003' }, { itemType: 'proof', itemId: 'proof_xyz' } ] }) console.log(`Order now has ${updated.itemCount} items`)
addItems(collectionId: string,
orderId: string,
data: ) → Promise<AddItemsResponse>removeItems
Remove specific items from an order. typescript const updated = await order.removeItems('coll_123', 'order_abc123', { itemIds: ['item_001', 'item_002'] })
removeItems(collectionId: string,
orderId: string,
data: ) → Promise<RemoveItemsResponse>lookup
Find all orders containing specific items (tags, proofs, or serial numbers). Use case: Scan a tag and immediately see if it's part of any order. typescript // Scan a tag and find associated orders const result = await order.lookup('coll_123', { items: [ { itemType: 'tag', itemId: 'TAG001' } ] }) if (result.orders.length > 0) { console.log(`Tag is part of ${result.orders.length} order(s)`) result.orders.forEach(ord => { console.log(`Order ${ord.orderRef}: ${ord.status}`) }) } // Batch lookup multiple items const batchResult = await order.lookup('coll_123', { items: [ { itemType: 'tag', itemId: 'TAG001' }, { itemType: 'serial', itemId: 'SN12345' }, { itemType: 'proof', itemId: 'proof_xyz' } ] })
lookup(collectionId: string,
data: ) → Promise<>query
Advanced query for orders with order-level and item-level filtering. More powerful than the basic list() function. typescript // Find pending orders created in January 2026 const result = await order.query('coll_123', { query: { status: 'pending', createdAfter: '2026-01-01T00:00:00Z', createdBefore: '2026-02-01T00:00:00Z', sortBy: 'createdAt', sortOrder: 'desc' }, limit: 50 }) // Find orders with specific metadata and item count const highPriority = await order.query('coll_123', { query: { metadata: { priority: 'high' }, minItemCount: 10, maxItemCount: 100 }, includeItems: true }) // Find orders containing a specific product batch const batchOrders = await order.query('coll_123', { query: { productId: 'prod_789', batchId: 'BATCH-2024-001' }, includeItems: true }) // Find an order containing one of several specific items const matched = await order.query('coll_123', { query: { items: [ { itemType: 'tag', itemId: 'TAG001' }, { itemType: 'serial', itemId: 'SN12345' } ] }, includeItems: true })
query(collectionId: string,
data: ) → Promise<>reports
Get reports and aggregations for orders. Provides analytics grouped by status, customer, product, date, etc. typescript // Get order counts by status const statusReport = await order.reports('coll_123', { groupByStatus: true }) console.log(statusReport.ordersByStatus) // { pending: 45, shipped: 123, completed: 789 } // Get comprehensive analytics const fullReport = await order.reports('coll_123', { groupByStatus: true, groupByProduct: true, includeItemStats: true, createdAfter: '2026-01-01T00:00:00Z' }) console.log(fullReport.itemStats?.avgItemsPerOrder) // Get top 10 customers by order count const topCustomers = await order.reports('coll_123', { groupByCustomer: true, topN: 10 })
reports(collectionId: string,
params?: ) → Promise<>findByProduct
Find all orders containing items with a specific product ID. Uses the automatic productSummary tracking in order metadata. typescript // Find all orders with a specific product const result = await order.findByProduct('coll_123', 'product_abc123', { limit: 50, includeItems: false }) result.orders.forEach(ord => { const count = ord.metadata.productSummary?.['product_abc123'] ?? 0 console.log(`Order ${ord.orderRef} has ${count} items of this product`) })
findByProduct(collectionId: string,
productId: string,
params?: ) → Promise<>getAnalytics
Get comprehensive scan analytics for all tags in an order. Returns scan counts, timestamps, locations, devices, and per-tag summaries. typescript const analytics = await order.getAnalytics('coll_123', 'order_abc123') if (analytics.analytics) { console.log(`Total scans: ${analytics.analytics.totalScans}`) console.log(`Admin scans: ${analytics.analytics.adminScans}`) console.log(`Created at: ${analytics.analytics.estimatedCreatedAt}`) console.log(`Unique locations: ${analytics.analytics.uniqueLocations}`) analytics.analytics.tagSummaries.forEach(tag => { console.log(`Tag ${tag.tagId}: ${tag.totalScans} scans`) }) }
getAnalytics(collectionId: string,
orderId: string) → Promise<>getTimeline
Get chronological timeline of all scan events for an order's tags. Supports filtering by date range and admin/customer scans. typescript // Get all scan events const timeline = await order.getTimeline('coll_123', 'order_abc123') timeline.timeline.forEach(event => { console.log(`${event.timestamp}: ${event.eventType} by ${event.isAdmin ? 'admin' : 'customer'}`) }) // Get admin scans only from last week const adminScans = await order.getTimeline('coll_123', 'order_abc123', { isAdmin: true, from: '2026-02-01T00:00:00Z', limit: 500 })
getTimeline(collectionId: string,
orderId: string,
params?: ) → Promise<>getLocationHistory
Get location-based scan history for an order's tags. Shows where the order's tags have been scanned. typescript const locations = await order.getLocationHistory('coll_123', 'order_abc123', { limit: 100 }) console.log(`Order scanned in ${locations.count} locations`) locations.locations.forEach(scan => { console.log(`${scan.location} at ${scan.timestamp}`) })
getLocationHistory(collectionId: string,
orderId: string,
params?: ) → Promise<>getBulkAnalytics
Get analytics summary for multiple orders at once. Efficient way to retrieve scan data for many orders. typescript const bulk = await order.getBulkAnalytics('coll_123', { orderIds: ['order_1', 'order_2', 'order_3'], from: '2026-01-01T00:00:00Z' }) bulk.results.forEach(result => { if (result.analytics) { console.log(`${result.orderRef}: ${result.analytics.totalScans} scans`) } })
getBulkAnalytics(collectionId: string,
data: ) → Promise<>getCollectionSummary
Get collection-wide analytics summary across all orders. Returns daily scan counts and admin activity overview. typescript // Get all-time collection summary const summary = await order.getCollectionSummary('coll_123') console.log(`Admin activity count: ${summary.adminActivity.count}`) console.log('Scans by day:') summary.scansByDay.forEach(day => { console.log(` ${day.date}: ${day.scanCount} scans`) }) // Get summary for last 30 days const recentSummary = await order.getCollectionSummary('coll_123', { from: '2026-01-08T00:00:00Z', to: '2026-02-08T00:00:00Z' })
getCollectionSummary(collectionId: string,
params?: ) → Promise<>findOrdersByProduct
Find all orders containing items from a specific product. Uses indexed queries for fast lookups across order items. typescript // Find all orders containing a product const { orders, limit, offset } = await order.findOrdersByProduct('coll_123', 'prod_789', { limit: 100 }) console.log(`Product appears in ${orders.length} orders`)
findOrdersByProduct(collectionId: string,
productId: string,
params?: ) → Promise<>findItemsByProduct
Get individual order items for a specific product. Returns all matching items with optional order summary. typescript // Get all items for a product const { items } = await order.findItemsByProduct('coll_123', 'prod_789', { includeOrder: true }) console.log(`Product delivered in ${items.length} order items`)
findItemsByProduct(collectionId: string,
productId: string,
params?: ) → Promise<>getOrderIdsByAttribute
Get unique order IDs containing items for a specific product. Lightweight query that only returns order IDs, not full order objects. typescript // Get order IDs for a product const productOrders = await order.getOrderIdsByAttribute( 'coll_123', 'productId', 'prod_789', { limit: 500 } )
getOrderIdsByAttribute(collectionId: string,
attribute: 'productId',
value: string,
params?: ) → Promise<>