Skip to main content

Prerequisites

Before installing, ensure you have:
  • A Constructor.io account with an API key
  • Node.js and npm/yarn/pnpm installed (for package manager installation)
  • A modern browser that supports the Fetch API
You can find your API key in your Constructor.io dashboard. Contact sales if you’d like to sign up, or support if your company already has an account.

Package Manager Installation

Install the SDK using your preferred package manager:
npm install @constructor-io/constructorio-client-javascript

Import in Your Application

Once installed, import or require the package:
import ConstructorioClient from '@constructor-io/constructorio-client-javascript';

const constructorio = new ConstructorioClient({
  apiKey: 'YOUR_API_KEY',
});
Never commit your API key to version control. Use environment variables or a secure configuration management system to store your API key.

Bundled Version (CDN)

For projects that don’t use a build system, you can use the pre-bundled version:

Step 1: Download the Bundle

The bundled version is available in the ./dist folder of the GitHub repository:
  • constructorio-client-javascript.js - Development version with comments
  • constructorio-client-javascript.min.js - Minified production version
Do not link directly to the GitHub-hosted version. Download the file and host it locally on your own server or CDN.

Step 2: Include in Your HTML

<!DOCTYPE html>
<html>
<head>
  <title>My Store</title>
</head>
<body>
  <!-- Your page content -->

  <!-- Include the bundled Constructor.io client -->
  <script src="/path/to/constructorio-client-javascript.min.js"></script>
  
  <script>
    // The client is available as ConstructorioClient on the window object
    const constructorio = new ConstructorioClient({
      apiKey: 'YOUR_API_KEY',
    });

    // Now you can use the client
    constructorio.search.getSearchResults('red shoes')
      .then(response => {
        console.log('Search results:', response);
      });
  </script>
</body>
</html>

Package Information

Package Name: @constructor-io/constructorio-client-javascriptCurrent Version: 2.75.1License: MITBundle Size: Check bundlephobia for current minified and gzipped size

Dependencies

The SDK has minimal dependencies:

Core Dependencies

  • @constructor-io/constructorio-id - Automatic client and session ID management
  • crc-32 - CRC32 checksum implementation

Peer Dependencies

  • @babel/runtime (^7.19.0) - Required for transpiled code
Most modern package managers will automatically install peer dependencies. If you encounter issues, install @babel/runtime manually:
npm install @babel/runtime

TypeScript Support

The SDK includes TypeScript type definitions out of the box:
package.json
{
  "types": "lib/types/index.d.ts"
}
No additional @types package is needed. TypeScript will automatically detect the type definitions when you import the client.

Verify Installation

To verify the installation was successful, create a simple test:
const ConstructorioClient = require('@constructor-io/constructorio-client-javascript');

const constructorio = new ConstructorioClient({
  apiKey: 'YOUR_API_KEY',
});

console.log('Constructor.io client initialized successfully!');
console.log('Available modules:', {
  search: !!constructorio.search,
  browse: !!constructorio.browse,
  autocomplete: !!constructorio.autocomplete,
  recommendations: !!constructorio.recommendations,
  tracker: !!constructorio.tracker,
  quizzes: !!constructorio.quizzes,
  agent: !!constructorio.agent,
});
You should see output confirming all modules are available.

Next Steps

Quickstart Guide

Follow our quickstart guide to make your first search request

Build docs developers (and LLMs) love