# Class SearchEndpoint

The `SearchEndpoint` class allows the framework to perform HTTP requests against the Search API (e.g., searching, getting query suggestions, getting the HTML preview of an item, etc.).

Note:

When writing custom code that interacts with the Search API, be aware that executing queries directly through an instance of this class will not trigger any query events.

In some cases, this may be what you want. However, if you do want query events to be triggered (e.g., to ensure that standard components update themselves as expected), use the `queryController` instance instead.

Additional documentation

  JavaScript Search Framework Endpoint

## Index

### Methods

- deleteSubscription
- exchangeHandshakeToken
- extensions
- facetSearch
- fetchBinary
- follow
- getAuthenticationProviderUri
- getBaseAlertsUri
- getBaseUri
- getDocument
- getDocumentHtml
- getDocumentText
- getExportToExcelLink
- getQuerySuggest
- getRawDataStream
- getViewAsDatastreamUri
- getViewAsHtmlUri
- isJsonp
- listFieldValues
- listFieldValuesBatch
- listFields
- listSubscriptions
- plan
- rateDocument
- search
- setRequestModifier
- tagDocument
- updateSubscription
- configureCloudEndpoint
- configureCloudV2Endpoint
- configureOnPremiseEndpoint
- configureSampleEndpoint
- configureSampleEndpointV2

### Properties

- endpoints

### Constructors

- constructor

## Methods

### deleteSubscription

- deleteSubscription(subscription: ISubscription, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<ISubscription>

- - Defined in rest/SearchEndpoint.ts :1050

  Deletes a subscription.

  #### Parameters

  - ##### subscription: ISubscription

    The subscription to delete.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<ISubscription>

### exchangeHandshakeToken

- exchangeHandshakeToken(options: IExchangeHandshakeTokenOptions, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<string>

- - Defined in rest/SearchEndpoint.ts :338

  Exchanges a temporary handshake token to either get an initial access token or extend the privileges of an existing access token.

  #### Parameters

  - ##### options: IExchangeHandshakeTokenOptions

  - ##### Optional callOptions: IEndpointCallOptions

  - ##### Optional callParams: IEndpointCallParameters

  #### Returns Promise<string>

  The access token.

### extensions

- extensions(callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<IExtension[]>

- - Defined in rest/SearchEndpoint.ts :789

  Lists all available query extensions for the search endpoint.

  #### Parameters

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<IExtension[]>

  A Promise of the extensions.

### facetSearch

- facetSearch(request: IFacetSearchRequest, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<IFacetSearchResponse>

- - Defined in rest/SearchEndpoint.ts :908

  Searches through the values of a facet.

  #### Parameters

  - ##### request: IFacetSearchRequest

    The request for which to search through the values of a facet.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<IFacetSearchResponse>

  A Promise of facet search results.

### fetchBinary

- fetchBinary(query: IQuery, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<ArrayBuffer>

- - Defined in rest/SearchEndpoint.ts :440

  Performs a search on the index and returns a Promise of `ArrayBuffer`.

  #### Parameters

  - ##### query: IQuery

    The query to execute. Typically, the query object is built using a `QueryBuilder`.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<ArrayBuffer>

  A Promise of query results.

### follow

- follow(request: ISubscriptionRequest, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<ISubscription>

- - Defined in rest/SearchEndpoint.ts :933

  Follows an item, or a query result, using the search alerts service.

  #### Parameters

  - ##### request: ISubscriptionRequest

    The subscription details.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<ISubscription>

### getAuthenticationProviderUri

- getAuthenticationProviderUri(provider: string, returnUri?: string, message?: string, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): string

- - Defined in rest/SearchEndpoint.ts :309

  Gets the URI that can be used to authenticate against the given provider.

  #### Parameters

  - ##### provider: string

    The provider name.

  - ##### Optional returnUri: string

    The URI to return to after the authentication is completed.

  - ##### Optional message: string

    The authentication message.

  - ##### Optional callOptions: IEndpointCallOptions

    Additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    Options injected by the applied decorators.

  #### Returns string

  The authentication provider URI.

### getBaseAlertsUri

- getBaseAlertsUri(): string

- - Defined in rest/SearchEndpoint.ts :294

  Gets the base URI of the search alerts endpoint.

  #### Returns string

  The base URI of the search alerts endpoint.

### getBaseUri

- getBaseUri(): string

- - Defined in rest/SearchEndpoint.ts :286

  Gets the base URI of the Search API endpoint.

  #### Returns string

  The base URI of the Search API endpoint.

### getDocument

- getDocument(documentUniqueID: string, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<IQueryResult>

- - Defined in rest/SearchEndpoint.ts :587

  Gets a single item, using its `uniqueId`.

  #### Parameters

  - ##### documentUniqueID: string

    Typically, the IQueryResult.uniqueId on each result.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<IQueryResult>

  A Promise of the item.

### getDocumentHtml

- getDocumentHtml(documentUniqueID: string, callOptions?: IViewAsHtmlOptions, callParams?: IEndpointCallParameters): Promise<HTMLDocument>

- - Defined in rest/SearchEndpoint.ts :648

  Gets the content for a single item, as an HTMLDocument (think: quickview).

  #### Parameters

  - ##### documentUniqueID: string

    Typically, the IQueryResult.uniqueId on each result.

  - ##### Optional callOptions: IViewAsHtmlOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<HTMLDocument>

  A Promise of the item content.

### getDocumentText

- getDocumentText(documentUniqueID: string, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<string>

- - Defined in rest/SearchEndpoint.ts :618

  Gets the content of a single item, as text (think: quickview).

  #### Parameters

  - ##### documentUniqueID: string

    Typically, the IQueryResult.uniqueId on each result.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<string>

  A Promise of the item content.

### getExportToExcelLink

- getExportToExcelLink(query: IQuery, numberOfResults: number, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): string

- - Defined in rest/SearchEndpoint.ts :486
  deprecated

    getExportToExcelLink does not factor in all query parameters (e.g. dynamic facets) due to GET request url length limitations. Please use `fetchBinary` instead to ensure all query parameters are used.

    Gets a link / URI to download a query result set to the XLSX format.

    Note:

    > This method does not automatically download the query result set, but rather provides an URI from which to download it.

  #### Parameters

  - ##### query: IQuery

    The query for which to get the XLSX result set.

  - ##### numberOfResults: number

    The number of results to download.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns string

  The download URI.

### getQuerySuggest

- getQuerySuggest(request: IQuerySuggestRequest, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<IQuerySuggestResponse>

- - Defined in rest/SearchEndpoint.ts :873

  Gets a list of query suggestions for a request.

  #### Parameters

  - ##### request: IQuerySuggestRequest

    The query, and the number of suggestions to return.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<IQuerySuggestResponse>

  A Promise of query suggestions.

### getRawDataStream

- getRawDataStream(documentUniqueId: string, dataStreamType: string, callOptions?: IViewAsHtmlOptions, callParams?: IEndpointCallParameters): Promise<ArrayBuffer>

- - Defined in rest/SearchEndpoint.ts :524

  Gets the raw datastream for an item. This is typically used to get a thumbnail for an item.

  Returns an array buffer.

  Example:

      let rawBinary = String.fromCharCode.apply(null, new Uint8Array(response));
      img.setAttribute('src', 'data:image/png;base64,' + btoa(rawBinary));

  #### Parameters

  - ##### documentUniqueId: string

    Typically, the IQueryResult.uniqueId on each result.

  - ##### dataStreamType: string

    Normally, `$Thumbnail`.

  - ##### Optional callOptions: IViewAsHtmlOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<ArrayBuffer>

### getViewAsDatastreamUri

- getViewAsDatastreamUri(documentUniqueID: string, dataStreamType: string, callOptions?: IViewAsHtmlOptions, callParams?: IEndpointCallParameters): string

- - Defined in rest/SearchEndpoint.ts :559

  Gets an URL from which it is possible to see the datastream for an item. This is typically used to get a thumbnail for an item.

  #### Parameters

  - ##### documentUniqueID: string

    Typically, the IQueryResult.uniqueId on each result.

  - ##### dataStreamType: string

    Normally, `$Thumbnail`.

  - ##### Default value callOptions: IViewAsHtmlOptions = {}

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns string

  The datastream URL.

### getViewAsHtmlUri

- getViewAsHtmlUri(documentUniqueID: string, callOptions?: IViewAsHtmlOptions, callParams?: IEndpointCallParameters): string

- - Defined in rest/SearchEndpoint.ts :685

  Gets an URL from which it is possible to see a single item content, as HTML (think: quickview).

  #### Parameters

  - ##### documentUniqueID: string

    Typically, the IQueryResult.uniqueId on each result.

  - ##### Optional callOptions: IViewAsHtmlOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns string

  The URL.

### isJsonp

- isJsonp(): boolean

- - Defined in rest/SearchEndpoint.ts :357

  Indicates whether the search endpoint is using JSONP internally to communicate with the Search API.

  #### Returns boolean

  `true` in the search enpoint is using JSONP; `false` otherwise.

### listFieldValues

- listFieldValues(request: IListFieldValuesRequest, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<IIndexFieldValue[]>

- - Defined in rest/SearchEndpoint.ts :706

  Lists the possible field values for a request.

  #### Parameters

  - ##### request: IListFieldValuesRequest

    The request for which to list the possible field values.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<IIndexFieldValue[]>

  A Promise of the field values.

### listFieldValuesBatch

- listFieldValuesBatch(request: IListFieldValuesBatchRequest, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<IIndexFieldValue[][]>

- - Defined in rest/SearchEndpoint.ts :739

  Lists the possible field values for a request.

  #### Parameters

  - ##### request: IListFieldValuesBatchRequest

    The request for which to list the possible field values.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<IIndexFieldValue[][]>

  A Promise of the field values.

### listFields

- listFields(callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<IFieldDescription[]>

- - Defined in rest/SearchEndpoint.ts :771

  Lists all fields for the index, and returns an array of their descriptions.

  #### Parameters

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<IFieldDescription[]>

  A Promise of the index fields and descriptions.

### listSubscriptions

- listSubscriptions(page?: number, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<ISubscription[]>

- - Defined in rest/SearchEndpoint.ts :962

  Gets a Promise of an array of the current subscriptions.

  #### Parameters

  - ##### Optional page: number

    The page of the subscriptions.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<ISubscription[]>

### plan

- plan(query: IQuery, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<ExecutionPlan>

- - Defined in rest/SearchEndpoint.ts :460

  Gets the plan of execution of a search request, without performing it.

  #### Parameters

  - ##### query: IQuery

    The query to execute. Typically, the query object is built using a `QueryBuilder`.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<ExecutionPlan>

  A Promise of plan results.

### rateDocument

- rateDocument(ratingRequest: IRatingRequest, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<boolean>

- - Defined in rest/SearchEndpoint.ts :812

  Note:

  > The Coveo Cloud V2 platform does not support collaborative rating. Therefore, this method is obsolete in Coveo Cloud V2.

  Rates a single item in the index (granted that collaborative rating is enabled on your index)

  #### Parameters

  - ##### ratingRequest: IRatingRequest

    The item id, and the rating to add.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<boolean>

### search

- search(query: IQuery, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<IQueryResults>

- - Defined in rest/SearchEndpoint.ts :393

  Performs a search on the index and returns a Promise of `IQueryResults`.

  This method slightly modifies the query results by adding additional information to each result (id, state object, etc.).

  #### Parameters

  - ##### query: IQuery

    The query to execute. Typically, the query object is built using a `QueryBuilder`.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<IQueryResults>

  A Promise of query results.

### setRequestModifier

- setRequestModifier(requestModifier: function): void

- - Defined in rest/SearchEndpoint.ts :278

  Sets a function which allows external code to modify all endpoint call parameters before the browser sends them.

  Note:

  > This is useful in very specific scenarios where the network infrastructure requires special request headers to be added or removed, for example.

  #### Parameters

  - ##### requestModifier: function

    The function.

    - - (params: IRequestInfo<any>): IRequestInfo<any>

      - #### Parameters

        - ##### params: IRequestInfo<any>

        #### Returns IRequestInfo<any>

  #### Returns void

### tagDocument

- tagDocument(taggingRequest: ITaggingRequest, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<boolean>

- - Defined in rest/SearchEndpoint.ts :842

  Tags a single item.

  #### Parameters

  - ##### taggingRequest: ITaggingRequest

    The item id, and the tag action to perform.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<boolean>

### updateSubscription

- updateSubscription(subscription: ISubscription, callOptions?: IEndpointCallOptions, callParams?: IEndpointCallParameters): Promise<ISubscription>

- - Defined in rest/SearchEndpoint.ts :1013

  Updates a subscription with new parameters.

  #### Parameters

  - ##### subscription: ISubscription

    The subscription to update with new parameters.

  - ##### Optional callOptions: IEndpointCallOptions

    An additional set of options to use for this call.

  - ##### Optional callParams: IEndpointCallParameters

    The options injected by the applied decorators.

  #### Returns Promise<ISubscription>

### Static configureCloudEndpoint

- configureCloudEndpoint(organization?: string, token?: string, uri?: string, otherOptions?: ISearchEndpointOptions): void

- - Defined in rest/SearchEndpoint.ts :143

  Configures a search endpoint on a Coveo Cloud V1 index.

  #### Parameters

  - ##### Optional organization: string

    The organization ID of your Coveo Cloud index.

  - ##### Optional token: string

    The token to use to execute query. If not specified, you will likely need to login when querying.

  - ##### Default value uri: string = "https://cloudplatform.coveo.com/rest/search"

    The URI of the Coveo Cloud REST Search API. By default, this points to the production environment.

  - ##### Optional otherOptions: ISearchEndpointOptions

    A set of additional options to use when configuring this endpoint.

  #### Returns void

### Static configureCloudV2Endpoint

- configureCloudV2Endpoint(organization?: string, token?: string, uri?: string, otherOptions?: ISearchEndpointOptions): void

- - Defined in rest/SearchEndpoint.ts :178

  Configures a new search endpoint on a Coveo Cloud V2 organization.

  #### Parameters

  - ##### Optional organization: string

    The unique identifier of the target Coveo Cloud V2 organization (e.g., `mycoveocloudv2organizationg8tp8wu3`).

  - ##### Optional token: string

    The access token to authenticate Search API requests with (i.e., an API key or a search token).

    Note: This token will also authenticate Usage Analytics Write API requests if the search interface initializes an `Analytics` component whose `token` option is unspecified.

  - ##### Default value uri: string = "https://platform.cloud.coveo.com/rest/search"

    The base URI of the Search API.

    Allowed values:

    - `https://platform.cloud.coveo.com/rest/search` (for organizations in the standard Coveo Cloud V2 environment)
    - `https://platform-eu.cloud.coveo.com/rest/search` (for organizations with European data residency)
    - `https://platform-au.cloud.coveo.com/rest/search` (for organizations with Australian data residency)
    - `https://platformhipaa.cloud.coveo.com/rest/search` (for HIPAA organizations)

    Default: `https://platform.cloud.coveo.com/rest/search`

  - ##### Optional otherOptions: ISearchEndpointOptions

    Additional options to apply for this endpoint (e.g., a `renewAccessToken` function).

  #### Returns void

### Static configureOnPremiseEndpoint

- configureOnPremiseEndpoint(uri: string, token?: string, otherOptions?: ISearchEndpointOptions): void

- - Defined in rest/SearchEndpoint.ts :194

  Configures a search endpoint on a Coveo on-premise index.

  #### Parameters

  - ##### uri: string

    The URI of your Coveo Search API endpoint (e.g., `http://myserver:8080/rest/search`)

  - ##### Optional token: string

    The token to use to execute query. If not specified, you will likely need to login when querying (unless your Coveo Search API endpoint is configured using advanced auth options, such as Windows auth or claims).

  - ##### Optional otherOptions: ISearchEndpointOptions

    A set of additional options to use when configuring this endpoint.

  #### Returns void

### Static configureSampleEndpoint

- configureSampleEndpoint(otherOptions?: ISearchEndpointOptions): void

- - Defined in rest/SearchEndpoint.ts :86

  Configures a demo search endpoint on a Coveo Cloud V1 organization whose index contains various types of non-secured items.

  Note: This method mainly exists for demo and testing purposes.

  #### Parameters

  - ##### Optional otherOptions: ISearchEndpointOptions

    Additional options to apply for this endpoint.

  #### Returns void

### Static configureSampleEndpointV2

- configureSampleEndpointV2(otherOptions?: ISearchEndpointOptions): void

- - Defined in rest/SearchEndpoint.ts :120

  Configures a demo search endpoint on a Coveo Cloud V2 organization whose index contains various types of non-secured items.

  Note: This method mainly exists for demo and testing purposes.

  #### Parameters

  - ##### Optional otherOptions: ISearchEndpointOptions

    Additional options to apply for this endpoint.

  #### Returns void

## Properties

### Static endpoints

endpoints: object

- Defined in rest/SearchEndpoint.ts :77

A map of all initialized `SearchEndpoint` instances.

Example: `Coveo.SearchEndpoint.endpoints["default"]` returns the default endpoint that was created at initialization.

type

  {{}}

#### Type declaration

- ##### [endpoint: string]: SearchEndpoint

## Constructors

### constructor

- new SearchEndpoint(options?: ISearchEndpointOptions): SearchEndpoint

- - Defined in rest/SearchEndpoint.ts :230

  Creates a new `SearchEndpoint` instance. Uses a set of adequate default options, and merges these with the `options` parameter. Also creates an `EndpointCaller` instance and uses it to communicate with the endpoint internally.

  #### Parameters

  - ##### Optional options: ISearchEndpointOptions

    The custom options to apply to the new `SearchEndpoint`.

  #### Returns SearchEndpoint

### Hierarchy

- SearchEndpoint

### Implements

- ISearchEndpoint