Connector for the Apex Trading platform - a comprehensive ERP solution for the cannabis and hemp industry
apexThis guide will help you get up and running with the Apex Trading connector.
Go to the root directory of your project.
Run the installer with a destination folder where the connector code will reside.
bash -i <(curl https://registry.514.ai/install.sh) --dest app/connectors/apex apex v1 514-labs typescript default
From your project's root directory:
pnpm install
The Apex Trading API uses Bearer token authentication. You'll need to obtain an API token from your Apex Trading account.
import { createConnector } from '@514labs/connector-apex'// Initialize the connectorconst conn = createConnector()conn.init({ accessToken: 'your_bearer_token_here'})// List batchesfor await (const page of conn.batches.list({ pageSize: 10 })) { console.log(`Fetched ${page.length} batches`) page.forEach(batch => { console.log(`Batch #${batch.id}`) })}The batches resource uses the v2 API endpoints.
// List batches with filtersfor await (const page of conn.batches.list({ updated_at_from: '2025-04-20T22:04:50Z', pageSize: 50, maxItems: 200})) { console.log(`Page with ${page.length} batches`)}// Get a single batchconst batch = await conn.batches.get(123)console.log('Batch:', batch)// Create a new batchconst newBatch = await conn.batches.create({ // batch data})// Update a batchconst updatedBatch = await conn.batches.update(123, { // updated fields})// List all buyersfor await (const page of conn.buyers.list({ pageSize: 20 })) { page.forEach(buyer => { console.log(`${buyer.name} (${buyer.buyer_type})`) })}// Filter by updated datefor await (const page of conn.buyers.list({ updated_at_from: '2025-01-01T00:00:00Z'})) { console.log(`Fetched ${page.length} recently updated buyers`)}// Get a single buyerconst buyer = await conn.buyers.get(456)console.log('Buyer:', buyer.name)// List all brandsfor await (const page of conn.brands.list()) { page.forEach(brand => { console.log(`${brand.name} - Company ${brand.company_id}`) })}// Get a single brandconst brand = await conn.brands.get(789)console.log('Brand:', brand)// List products with filtersfor await (const page of conn.products.list({ updated_at_from: '2025-05-01T00:00:00Z', has_available_batches: true, include_sold_out_batches: false, pageSize: 25})) { console.log(`Fetched ${page.length} products`)}// Get a single productconst product = await conn.products.get(101)// Create a productconst newProduct = await conn.products.create({ // product data})// Update a productconst updatedProduct = await conn.products.update(101, { // updated fields})The connector handles pagination automatically. You control pagination behavior with:
pageSize: Number of items per page (default: 15, max: 500)maxItems: Maximum total items to fetch (optional)// Fetch first 100 items, 25 at a timefor await (const page of conn.batches.list({ pageSize: 25, maxItems: 100 })) { console.log(`Page with ${page.length} items`)}// Fetch all items, 500 at a time (most efficient)for await (const page of conn.batches.list({ pageSize: 500})) { console.log(`Page with ${page.length} items`)}try { const batch = await conn.batches.get(999) console.log('Batch:', batch)} catch (error) { if (error.statusCode === 404) { console.log('Batch not found') } else if (error.statusCode === 401) { console.log('Authentication failed') } else { console.log('Error:', error.message) }}The Apex API has a rate limit of 15 requests per second. The connector automatically enforces this:
conn.init({ accessToken: 'token', rateLimit: { requestsPerSecond: 15 // Default }})Enable logging for debugging:
conn.init({ accessToken: 'token', logging: { enabled: true, level: 'info', includeQueryParams: true }})// Logs will show:// - HTTP requests with method, URL, and query params// - HTTP responses with status and duration// - Errors and retriesUse environment variables for credentials:
# .env APEX_ACCESS_TOKEN=your_bearer_token_here
import { createConnector } from '@514labs/connector-apex'const conn = createConnector()conn.init({ accessToken: process.env.APEX_ACCESS_TOKEN!})