JavaScript Search Framework Tutorial 8: Configuring Your Own Search Endpoint

In the previous tutorials, you used a sample search endpoint to query an index containing public items.

In this tutorial, you’ll create a Coveo Cloud organization and provision its index by creating one or more sources. You’ll then configure a search endpoint against this new organization.

If you modified the ./bin/index.html page in previous tutorials, you can undo these changes by rebuilding the project.

To do so, run the following command line from the root of the tutorial project folder:

npm run build

Step 1: Create a Coveo Cloud Test Organization

The easiest way to create a Coveo Cloud test organization is to perform a simple HTTP POST request through Swagger UI.

  1. Access the Create organization REST endpoint.

  2. Authorize Swagger UI to execute API calls against the Coveo Cloud Platform:

    1. In the upper-right corner of the endpoint card, if you see a red ! icon (**!**), click it.

      If you see a blue i icon (i) instead, then you have already authorized Swagger UI to execute requests. You can skip 2.b and 2.c.

    2. In the Available authorizations dialog, click Authorize. This will redirect your browser to the Coveo Cloud Platform login page.

    3. Log in to the Coveo Cloud Platform using one of the supported identity providers (Google, Office 365, or Salesforce). This will redirect your browser back to Swagger UI.

  3. In the name field, enter a suitable name for your new organization (e.g., My Test Organization).

  4. In the organizationTemplate field, enter Developer.

  5. Click Try it out!

If the request is successful (i.e., 201 Created status), the response body will contain your unique and permanent organization ID. Copy this value, as you’ll need it in step 4.

Step 2: Create a Public Source

A source is a named, persistent set of options that tells a connector how and when to index original content from a given repository. In the Coveo Cloud Administration Console, let’s create a new source in your organization to index public content (e.g., a Web source whose content is accessible to everyone).

  1. On the Sources page, click Add Source.

    Click add source

  2. Select Web > Web Cloud.

    Select Web Cloud

    The Cloud and Crawling Module tags refer to the way in which the connector retrieves data.

  3. In the Configuration tab, enter the following:

    • Source name: Example (Web)

    • Site URL: https://example.com

  4. Click Add and Build Source.

    Configure and build source

Assuming this is the first time you build a source in your organization, the platform will now initialize your index. This is a one-time process called provisioning, and it takes about 15 minutes. You can monitor the process by expanding the Status panel.

Monitor provisioning

When the provisioning process is complete, your source status will become Performing rebuild.

Performing rebuild status

Step 3: Create an API Key

Next, let’s create an API key that only grants specific privileges in your organization.

  1. On the API Keys page, click Add Key.

    Click Add API Key

  2. In the Configuration tab, enter the following:

    • Key name: Example Key

    • Description: API key to configure your own search endpoint

    Configure API Key

  3. In the Privileges tab, grant the following privileges:

    Service Domain Access level
    Analytics Analytics data Push
    Search Execute queries Allowed

    For example, the following figure shows how to grant Push-level permissions on the Analytics data domain.

    Grant API Key Privileges

  4. Click Add Key.

Copy the generated API key value, as you’ll need it in step 4.

The only time you can retrieve the value of an API key is from the Your Key panel when you create it. You should copy the key to a safe location of your choice.

Step 4: Configure Your Search Endpoint

In the ./bin/index.html file, change the following line:

Coveo.SearchEndpoint.configureSampleEndpointV2();

to:

Coveo.SearchEndpoint.configureCloudV2Endpoint(
  "MY_ORGANIZATION_ID",
  "MY_API_KEY"
);

where you replace:

  • MY_ORGANIZATION_ID with the organization ID you got in step 1*.

    *If you did not copy the organization ID when you created your organization, you can still retrieve it.

  • MY_API_KEY with the API key you got in step 3.

See JavaScript Search Framework Endpoints.

If you open the search page in your browser, you should now be able to query the index of your newly created organization. Since you only indexed https://example.com, there won’t be much in your index. You can create other sources to add more content to your organization. To learn more about indexing, see Platform Developer Tutorial 1.

  • While the Coveo Cloud Platform is creating the index, the organization has no accessible search endpoint. Thus, until the index is ready (which may take a few minutes), any search request you send will return a 408 Request Timeout error with the NoEndPointException message.

  • Although exposing an API key in client-side code is typically considered a bad practice, API Key Authentication can in fact be a legitimate option if your index only contains public items. However, as soon as your index contains secured items (i.e., items that should only be visible to certain authenticated users), you must instead implement search token authentication.

What’s Next?

If you plan to design your own custom components, you should now proceed to JavaScript Search Framework Tutorial 9: Advanced Integration With Custom TypeScript Component (Configuration).

Recommended Articles