-
Tutorials
- 0: Environment Setup
- 1: Basic Configuration, Options, and Markup
- 2: Interact With the Search Interface and Component Instances
- 3: Understanding the Event System
- 4: Modify the Query
- 5: Result Templates
- 6: Usage Analytics
- 7: Interact With Component States
- 8: Configure Your Own Search Endpoint
- 9: Advanced Integration With Custom TypeScript Component (Configuration)
- 10: Advanced Integration With Custom TypeScript Component (Implementation)
JavaScript Search Framework Tutorial 8: Configure 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 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.
-
Access the Create organization REST endpoint.
-
Authorize Swagger UI to execute API calls against the Coveo Platform:
-
In the upper-right corner of the endpoint card, if you see a red
!
icon, click it.
If you see a blue
i
iconinstead, then you have already authorized Swagger UI to execute requests. You can skip 2.b and 2.c.
-
In the Available authorizations dialog, click Authorize. This will redirect your browser to the Coveo Platform login page.
-
Log in to the Coveo Platform using one of the supported identity providers (Google, Office 365, or Salesforce). This will redirect your browser back to Swagger UI.
-
-
In the name field, enter a suitable name for your new organization (e.g.,
My Test Organization
). -
In the organizationTemplate field, enter
Developer
. -
Click Execute.
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 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).
-
On the Sources page, click Add Source.
-
Select Web > Web Cloud.
The
Cloud
andCrawling Module
tags refer to the way in which the connector retrieves data. -
In the Configuration tab, enter the following:
-
Source name:
Example (Web)
-
Site URL:
https://example.com
-
-
Click Add 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.
When the provisioning process is complete, your source status will become Performing rebuild.
Step 3: Create an API Key
Next, let’s create an API key that only grants specific privileges in your organization.
-
On the API Keys page, click Add Key.
-
In the Configuration tab, enter the following:
-
Key name:
Example Key
-
Description:
API key to configure your own search endpoint
-
-
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.
-
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 didn’t 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.
-
While the Coveo Platform is creating the index, the organization has no accessible search endpoint. Therefore, until the index is ready (which may take a few minutes), any search request you send will return a
408 Request Timeout
error with theNoEndPointException
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).