For the complete documentation index, see llms.txt. This page is also available as Markdown.

First request

This page searches foods from the browser and renders the names.

1. Add the request

Create src/january-quickstart.ts next to the src/january.ts from Authentication:

import { JanuaryError } from '@januaryai/web-sdk';
import { createJanuaryClient } from './january';
import { getAppSession } from './session';

const january = createJanuaryClient();

export async function renderJanuaryQuickStart(output: HTMLElement): Promise<void> {
  const session = await getAppSession();
  const user = january.forUser({
    endUserId: session.endUserId,
    endUserTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
  });

  try {
    const { items } = await user.foods.search({ query: 'greek yogurt', limit: 5 });
    output.textContent = items.map((food) => food.name).join(', ');
  } catch (error) {
    if (error instanceof JanuaryError) {
      console.error('January request failed', {
        category: error.category,
        status: error.status,
        code: error.code,
        requestId: error.requestId,
        cause: error.cause,
      });
    }
    throw error;
  }
}

The token decides which user January acts for; the SDK doesn't send endUserId to January. Still set it to your opaque user ID, never an email address or name (User identity and timezone).

2. Run it

Call the function once the user is signed in, then start your development server:

#january-results shows up to five food names. If the request fails, the console shows the error's category, status, code, request ID, and cause; Error handling says what each category means.

Next: React example app

Last updated

Was this helpful?