Configure the SDK client with an API key or JWT.

Setup & Authentication

Setup & Authentication

Create a client

Import FlashoClient and initialise it with your credentials. The client is safe to create once and reuse for the lifetime of your application.

import { FlashoClient } from 'flasho-merchant-sdk';
 
const flasho = new FlashoClient({ apiKey: 'flsh_YOUR_KEY' });

Options

OptionTypeDescription
apiKeystringAPI key starting with flsh_ — for server/website integrations
tokenstringJWT — for mobile app integrations
baseUrlstringOverride the API base URL (default: https://vendors.tryflasho.com)

Either apiKey or token is required. Providing neither throws immediately.

Option A — API key (servers & websites)

The recommended method. Generate a key in your Flasho dashboard under Website API.

const flasho = new FlashoClient({
  apiKey: process.env.FLASHO_API_KEY!,
});

💡 Keep your key secret

Store the API key in an environment variable. Never hard-code it in client-side JavaScript or commit it to version control.

Option B — JWT (mobile apps)

Log in with dashboard email and password. The SDK stores the token automatically for all subsequent calls.

const flasho = new FlashoClient({ token: 'placeholder' });
 
const { token, merchant } = await flasho.auth.login({
  email: '[email protected]',
  password: 'your-password',
});
 
// All calls after this point use the JWT automatically
const data = await flasho.account.bootstrap();

Next.js / server components

// lib/flasho.ts
import { FlashoClient } from 'flasho-merchant-sdk';
 
// Create once — module-level singleton
export const flasho = new FlashoClient({
  apiKey: process.env.FLASHO_API_KEY!,
});
// app/api/book/route.ts
import { flasho } from '@/lib/flasho';
import { NextResponse } from 'next/server';
 
export async function POST(req: Request) {
  const body = await req.json();
  const { delivery } = await flasho.deliveries.create(body);
  return NextResponse.json({ delivery });
}

Error handling

All SDK methods throw typed errors you can catch and inspect.

import { FlashoApiError, FlashoNetworkError } from 'flasho-merchant-sdk';
 
try {
  const { delivery } = await flasho.deliveries.create({ ... });
} catch (err) {
  if (err instanceof FlashoApiError) {
    // HTTP error from the API
    console.error(`${err.status}: ${err.apiMessage}`);
 
    if (err.isUnauthorized)    { /* invalid API key */ }
    if (err.isValidationError) { /* bad request body */ }
    if (err.isNotFound)        { /* delivery not found */ }
 
  } else if (err instanceof FlashoNetworkError) {
    // No response received — network issue
    console.error('Network failure:', err.message);
  }
}
Error classWhen thrown
FlashoApiErrorAPI returned a non-2xx HTTP status
FlashoNetworkErrorRequest failed before a response was received

FlashoApiError properties: status (HTTP code), apiMessage (string from API), isUnauthorized, isValidationError, isNotFound.