Documentation/ Developers/ Integration Guide

Integration Guide

Build custom integrations with Organiko.ai's platform

Overview

This guide will help you build custom integrations with Organiko.ai, whether you're connecting a new accounting system, e-commerce platform, or building entirely custom workflows.

💡
Before You Start
Make sure you have an Organiko.ai account and API credentials. Check out our Quick Start Guide to get set up.

Common Integration Patterns

1. Sync Purchase Orders

Automatically sync purchase orders from your accounting system or procurement platform into Organiko.ai for organic compliance tracking.

Flow:
• External system creates/updates PO
• Webhook or polling detects changes
• POST to /orders/purchase
• Organiko.ai processes compliance data

2. Sync Sales Orders

Import sales orders from e-commerce platforms (Shopify, WooCommerce, Amazon) for allocation and certification tracking.

Flow:
• Customer places order on e-commerce platform
• Webhook triggers on order creation
• POST to /orders/sales
• Organiko.ai allocates certified inventory

3. Inventory Management

Keep inventory levels in sync between your warehouse management system and Organiko.ai.

Flow:
• Inventory adjustment in WMS
• Sync via webhook or scheduled job
• PUT to /inventory/products/:id
• Bidirectional sync maintains consistency

4. Real-time Event Processing

Use webhooks to react to events in Organiko.ai (certifications, allocations, compliance alerts).

Flow:
• Event occurs in Organiko.ai
• Webhook POST to your endpoint
• Your system processes event
• Update external systems as needed

Step-by-Step Integration

1

Authentication Setup

Implement OAuth authentication flow or use API credentials to obtain access tokens.

// Example: Get access token const response = await fetch('https://api.organiko.ai/v1/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: process.env.ORGANIKO_EMAIL, password: process.env.ORGANIKO_PASSWORD, }), }); const { access_token } = await response.json();
2

Data Mapping

Map fields from your source system to Organiko.ai's data model.

// Example: Map external order to Organiko format function mapOrderData(externalOrder) { return { external_id: externalOrder.id, order_number: externalOrder.orderNumber, order_date: externalOrder.createdAt, supplier: { name: externalOrder.vendor.name, email: externalOrder.vendor.email, }, line_items: externalOrder.items.map(item => ({ product_name: item.name, quantity: item.quantity, unit: item.unit, certification: item.organicCert, })), }; }
3

API Integration

Make API calls to sync data with proper error handling and retry logic.

// Example: Create purchase order async function syncPurchaseOrder(orderData) { const response = await fetch('https://api.organiko.ai/v1/orders/purchase', { method: 'POST', headers: { 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json', }, body: JSON.stringify(orderData), }); if (!response.ok) { throw new Error(`API error: ${response.status}`); } return await response.json(); }
4

Webhook Setup (Optional)

Register webhook endpoints to receive real-time updates from Organiko.ai.

// Example: Register webhook endpoint const webhook = await fetch('https://api.organiko.ai/v1/webhooks', { method: 'POST', headers: { 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ url: 'https://your-server.com/webhooks/organiko', events: ['order.certified', 'inventory.updated'], secret: 'your-webhook-secret', }), });
5

Error Handling & Logging

Implement comprehensive error handling and logging for production reliability.

// Example: Retry logic with exponential backoff async function syncWithRetry(fn, maxRetries = 3) { for (let i = 0; i < maxRetries; i++) { try { return await fn(); } catch (error) { console.error(`Attempt ${i + 1} failed:`, error); if (i === maxRetries - 1) throw error; const delay = Math.pow(2, i) * 1000; await new Promise(resolve => setTimeout(resolve, delay)); } } }

Best Practices

Use Idempotent Requests

Include an idempotency_key in POST requests to prevent duplicate processing if requests are retried.

Implement Exponential Backoff

Use exponential backoff for retries when encountering rate limits or temporary failures.

Cache Access Tokens

Access tokens are valid for 60 minutes. Cache them and only refresh when they expire.

Verify Webhook Signatures

Always verify webhook signatures to ensure requests are from Organiko.ai.

Store External IDs

Use the external_id field to maintain references to records in your source system.

Monitor Rate Limits

Check rate limit headers (X-RateLimit-Remaining) and implement backoff when approaching limits.

Test in Sandbox Mode

Use sandbox API credentials during development to test without affecting production data.

Testing Your Integration

1. Unit Testing

Test data mapping functions and API request formatting:

// Example: Jest test test('maps external order to Organiko format', () => { const external = { id: '123', orderNumber: 'PO-001' }; const mapped = mapOrderData(external); expect(mapped.external_id).toBe('123'); expect(mapped.order_number).toBe('PO-001'); });

2. Integration Testing

Test against Organiko.ai's sandbox environment with test data before going to production.

3. Error Scenario Testing

Test how your integration handles API errors, rate limits, and network failures.

Common Challenges & Solutions

Challenge: Data Model Differences

Problem: Your source system's data model doesn't match Organiko.ai's structure.

Solution: Create a transformation layer that maps between the two models. Use the external_id field to maintain relationships.

Challenge: Handling Duplicates

Problem: Same record might be synced multiple times.

Solution: Use external_id to check for existing records. Update instead of create if record exists.

Challenge: Rate Limit Errors

Problem: Hitting rate limits during bulk syncs.

Solution: Implement batching, respect rate limit headers, and use exponential backoff. Consider upgrading your plan for higher limits.