Quick Start

This guide explains how to initialize the Youzu SDK and set up authentication using session tokens.

Youzu Object OverviewCopied!

The Youzu SDK exposes a global Youzu object on the Window interface, providing authentication and session management utilities for interacting with the Youzu API.

Available FunctionsCopied!

setClientIdCopied!

Sets the client identifier in API request headers.

Youzu.setClientId(clientId)

Parameters:

  • clientId (string): The client identifier to be set

Implementation Details:

  • Sets the 'X-Client-Id' header in the configuration object
  • Required for identifying your application to the Youzu API

setSessionTokensCopied!

Handles authentication by setting up access tokens and automatic token refresh.

Youzu.setSessionTokens(accessToken, refreshToken)

Parameters:

  • accessToken (string): Initial access token for API authorization
  • refreshToken (string): Initial refresh token used for obtaining new access tokens when the current one expires

Implementation Details:

  • Clears any existing refresh interval to prevent multiple refresh cycles
  • Sets the Authorization header with the provided access token
  • Makes an immediate token refresh request to verify tokens
  • Sets up an automatic token refresh interval (every 5 minutes)
  • Updates the Authorization header with new tokens when refreshed

Usage ExampleCopied!

Here's how to initialize the SDK and set up authentication:

// Initialize with client ID
Youzu.setClientId('your-client-id');

// Set up session tokens (after user authenticates)
Youzu.setSessionTokens(
  'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...', // access token
  'refresh-token-value' // refresh token
);

// The SDK is now authenticated and will automatically refresh tokens

For more information about obtaining tokens, see the Session Tokens Authentication Guide.