Quick Start
Quick Start
Section titled “Quick Start”Get up and running with Arky in 5 minutes. This guide shows you how to initialize the SDK and start fetching data immediately.
Installation
Section titled “Installation”npm install arky-sdkSDK Initialization Patterns
Section titled “SDK Initialization Patterns”Pattern 1: Client-Side with Guest Token (Browsing Products/Services)
Section titled “Pattern 1: Client-Side with Guest Token (Browsing Products/Services)”Perfect for public data like product listings, service browsing, and CMS content.
import { createArkySDK } from 'arky-sdk';
const sdk = createArkySDK({ baseUrl: 'https://api.arky.io', businessId: 'your-business-id', market: 'us', storageUrl: 'https://storage.arky.io',
autoGuest: true, // Automatically creates guest token on first request
getToken: () => ({ accessToken: localStorage.getItem('accessToken') || '', refreshToken: localStorage.getItem('refreshToken') || '', provider: 'GUEST', expiresAt: parseInt(localStorage.getItem('expiresAt') || '0'), }),
setToken: (tokens) => { localStorage.setItem('accessToken', tokens.accessToken); if (tokens.refreshToken) localStorage.setItem('refreshToken', tokens.refreshToken); if (tokens.expiresAt) localStorage.setItem('expiresAt', tokens.expiresAt.toString()); },
logout: () => { localStorage.removeItem('accessToken'); localStorage.removeItem('refreshToken'); localStorage.removeItem('expiresAt'); },});
// Now you can fetch data immediatelyconst { items: products } = await sdk.eshop.getProducts({ status: 'ACTIVE', limit: 20 });Pattern 2: Server-Side with API Key (SSR in Astro/Next.js)
Section titled “Pattern 2: Server-Side with API Key (SSR in Astro/Next.js)”For server-side rendering where you need to fetch data at build time or on request.
// In Astro, Next.js, or other SSR environmentsimport { createArkySDK } from 'arky-sdk';
const sdk = createArkySDK({ baseUrl: 'https://api.arky.io', businessId: 'your-business-id', market: 'us', storageUrl: 'https://storage.arky.io',
autoGuest: false, // Don't create guest tokens on server
getToken: () => ({ accessToken: process.env.ARKY_API_KEY || '', // Server API key provider: 'API', expiresAt: 0, }),
setToken: () => {}, // No-op on server logout: () => {},});
// Fetch CMS content for SSRconst collection = await sdk.cms.getCollection({ id: 'website' });const { items: posts } = await sdk.cms.getCollectionEntries({ collectionId: 'blog', limit: 10 });Pattern 3: Authenticated User (Checkout, Bookings, Account Management)
Section titled “Pattern 3: Authenticated User (Checkout, Bookings, Account Management)”After user logs in, attach their auth token to enable protected operations.
const sdk = createArkySDK({ baseUrl: 'https://api.arky.io', businessId: 'your-business-id', market: 'us', autoGuest: false, // We'll handle auth manually
getToken: () => ({ accessToken: localStorage.getItem('userToken') || '', refreshToken: localStorage.getItem('refreshToken') || '', provider: 'EMAIL', // or 'GOOGLE' expiresAt: parseInt(localStorage.getItem('expiresAt') || '0'), }),
setToken: (tokens) => { localStorage.setItem('userToken', tokens.accessToken); if (tokens.refreshToken) localStorage.setItem('refreshToken', tokens.refreshToken); if (tokens.expiresAt) localStorage.setItem('expiresAt', tokens.expiresAt.toString()); },
logout: () => { localStorage.clear(); window.location.href = '/login'; },});
// Login firstconst auth = await sdk.user.loginUser({ password: 'password', provider: 'EMAIL',});// Tokens automatically stored via setToken
// Now you can do protected operationsconst user = await sdk.user.getMe({});const result = await sdk.eshop.checkout({ items: cartItems, paymentMethod: 'CREDIT_CARD' });Make Your First Request
Section titled “Make Your First Request”Fetch Business Information
Section titled “Fetch Business Information”// Using the SDKconst business = await sdk.business.getBusiness({});console.log('Business name:', business.name);console.log('Markets:', business.configs.markets);# Using HTTP directlycurl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ https://api.arky.io/v1/businesses/YOUR_BUSINESS_IDFetch CMS Content
Section titled “Fetch CMS Content”// Get a collection (e.g., blog posts)const collection = await sdk.cms.getCollection({ id: 'blog' });
// Get entries from the collectionconst { items: posts } = await sdk.cms.getCollectionEntries({ collectionId: 'blog', limit: 10,});
posts.forEach(post => { const title = sdk.utils.getBlockTextValue( post.blocks.find(b => b.key === 'title'), 'en' // locale ); console.log('Post:', title);});# Get collectioncurl https://api.arky.io/v1/businesses/YOUR_BUSINESS_ID/collections/blog
# Get entriescurl "https://api.arky.io/v1/businesses/YOUR_BUSINESS_ID/entries?owner=collection:blog&limit=10"Fetch Products
Section titled “Fetch Products”// List productsconst { items: products } = await sdk.eshop.getProducts({ status: 'ACTIVE', limit: 20,});
products.forEach(product => { const price = sdk.utils.getMarketPrice( product.variants[0].prices, 'us' // market code lowercase ); console.log(`${product.name}: ${price}`);});# List productscurl "https://api.arky.io/v1/businesses/YOUR_BUSINESS_ID/products?status=ACTIVE&limit=20"Framework Support
Section titled “Framework Support”Arky works with any JavaScript/TypeScript framework:
- React / Next.js
- Vue / Nuxt
- Svelte / SvelteKit
- Astro
- Angular
- Vanilla JS/TS
- Node.js / Express / Fastify
- Any other JavaScript environment
The SDK is framework-agnostic - just import and use it.
Authentication Strategies
Section titled “Authentication Strategies”Guest Mode (Public Data)
Section titled “Guest Mode (Public Data)”Enable autoGuest: true (default) to automatically create a guest token for unauthenticated requests:
const sdk = createArkySDK({ autoGuest: true, // ... other config});// Guest token is auto-created on first requestEmail & Password
Section titled “Email & Password”// Register a new userconst user = await sdk.user.registerUser({ name: 'John Doe', password: 'securePassword123',});
// Loginconst tokens = await sdk.user.loginUser({ password: 'securePassword123', provider: 'EMAIL',});
// Store tokenssdk.setToken(tokens);OAuth (Google)
Section titled “OAuth (Google)”// Get OAuth URLconst { url } = await sdk.user.getLoginUrl({ provider: 'GOOGLE', originUrl: window.location.origin, redirectUrl: `${window.location.origin}/auth/callback`,});
// Redirect user to Googlewindow.location.href = url;
// On callback page, exchange code for tokensconst tokens = await sdk.user.loginUser({ provider: 'GOOGLE', code: urlParams.get('code'), originUrl: window.location.origin,});
sdk.setToken(tokens);API Keys (Server-Side)
Section titled “API Keys (Server-Side)”For server-side or backend integrations, use API keys:
const sdk = createArkySDK({ baseUrl: 'https://api.arky.io', businessId: 'your-business-id', market: 'US', getToken: async () => ({ accessToken: process.env.ARKY_API_KEY, provider: 'API', // Important: signals X-API-Key header usage }), setToken: () => {}, // No-op for API keys logout: () => {}, autoGuest: false,});Next Steps
Section titled “Next Steps”- Core Concepts: Understand Businesses, Markets, Blocks, and more
- Business API: Manage business settings and configuration
- CMS API: Work with collections and entries
- E-shop API: Build your storefront
- SDK Guide: Advanced SDK usage and utilities