E-commerce Integration

Guide

Sync your e-commerce platform (Shopify, WooCommerce, etc.) with Glance to keep customers, orders, and inventory in sync.

Overview

A typical e-commerce integration involves syncing three data flows:

1

Customers

Sync customers from your store to Glance as Clients

2

Orders

Create invoices in Glance when orders are placed

3

Inventory

Keep stock levels synchronized in real-time

Step 1: Customer Sync

When a new customer registers or places an order on your store, create or update them in Glance:

Node.js SDK
// Check if client exists by email
const { data: existing } = await glance.clients.list({
  email: customer.email,
});

if (existing.length === 0) {
  await glance.clients.create({
    name: customer.name,
    email: customer.email,
    type: "MURSHE",
    contact: {
      firstName: customer.firstName,
      lastName: customer.lastName,
      phoneNumber: customer.phone,
      email: customer.email,
    },
  });
}
REST API equivalent
JavaScript
// Check if client exists by email
const existing = await fetch(
  "https://api.glance.co.il/clients?email=" + customer.email,
  { headers: { Authorization: `Bearer ${API_KEY}` } }
).then(r => r.json());

if (existing.data.length === 0) {
  // Create new client
  await fetch("https://api.glance.co.il/clients/create", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      name: customer.name,
      email: customer.email,
      type: "MURSHE",
      contact: {
        firstName: customer.firstName,
        lastName: customer.lastName,
        phoneNumber: customer.phone,
        email: customer.email,
      },
    }),
  });
}

Step 2: Order to Invoice

When an order is placed, create an invoice (or invoiceReceipt if payment is already collected):

Node.js SDK
const { data: doc } = await glance.documents.create("invoiceReceipt", {
  client: {
    name: order.customer.name,
    email: order.customer.email,
  },
  identifyClientBy: "email",
  products: order.items.map(item => ({
    description: item.name,
    sku: item.sku,
    units: item.quantity,
    price: item.price,
  })),
  payments: [{
    amount: order.total,
    paymentMethod: "creditCard",
    date: order.createdAt.split("T")[0],
  }],
  sendToClient: true,
});
REST API equivalent
JavaScript
await fetch("https://api.glance.co.il/documents/create/invoiceReceipt", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    client: {
      name: order.customer.name,
      email: order.customer.email,
    },
    identifyClientBy: "email",
    products: order.items.map(item => ({
      description: item.name,
      sku: item.sku,
      units: item.quantity,
      price: item.price,
    })),
    payments: [{
      amount: order.total,
      paymentMethod: "creditCard",
      date: order.createdAt.split("T")[0],
    }],
    sendToClient: true,
  }),
});

Step 3: Inventory Sync

Keep inventory levels synchronized between your store and Glance. You can either poll the inventory endpoint or use webhooks (coming soon) for real-time updates.

Tip: Use GET /products/sku/:sku to look up products by their SKU, which is typically the same across your store and Glance.

Best Practices

  • Use identifyClientBy to match customers by email or tax ID
  • Use invoiceReceipt type when payment is already collected
  • Always include sku in document products for inventory tracking
  • Implement idempotency by checking if a document already exists before creating
  • Use pagination to sync large product catalogs in batches