# Sending Queries to the Query API

## Overview <a href="#front-endintegrationspecification-usingthefredhopperqueryapi" id="front-endintegrationspecification-usingthefredhopperqueryapi"></a>

The basic concept is that the query string instructs FAS where the user is on the website, including any actions they have taken, and the response will confirm what items should be displayed. The recommended best practice is to use the HTTPS protocol to query the REST API endpoint and return a JSON-format response with gzip compression enabled.

### Accessing the Fredhopper Query API <a href="#front-endintegrationspecification-accessingthefredhopperqueryapi" id="front-endintegrationspecification-accessingthefredhopperqueryapi"></a>

Fredhopper Managed Services provides query access via the following URL template - 'query.\<configuration state>.\<service instance>.\<service>.\<region>.fredhopperservices.com'. The URLs for your specific implementation will be given to you by your Technical Consultant. The query API supports access either via SOAP (WSDL) and REST (XML or JSON). It is important to note that each instance of FAS has a published and a pre-published configuration state, which are independent from each other. This allows the possibility to test and confirm different configurations on the pre-published environment before they are pushed to the published endpoint.

Please see the example endpoints below which will connect to the live1 instance of FAS for a customer in our EU1 region:

#### REST (XML/JSON)

{% code title="Published Configuration" overflow="wrap" %}

```
https://query.published.live1.fas.eu1.fredhopperservices.com/fredhopper/query
```

{% endcode %}

{% code title="Pre-Published Configuration" overflow="wrap" %}

```
https://query.prepublished.live1.fas.eu1.fredhopperservices.com/fredhopper/query
```

{% endcode %}

#### SOAP (WSDL)

{% code title="Published Configuration" overflow="wrap" %}

```
https://query.published.live1.fas.eu1.fredhopperservices.com/fredhopper-ws/services/FASWebService 
```

{% endcode %}

{% code title="Pre-Published Configuration" overflow="wrap" %}

```
https://query.prepublished.live1.fas.eu1.fredhopperservices.com/fredhopper-ws/services/FASWebService
```

{% endcode %}

The authentication of each request that is sent through is handled via [HTTP Basic Access Authentication](http://en.wikipedia.org/wiki/Basic_access_authentication). Please see the 'Front-end Integration Tutorial' on the [Crownpeak Support Centre](https://support.crownpeak.com/hc/en-us/sections/11135345237917-Integration-Guides) for examples.

{% hint style="info" %}
Fredhopper supports query access[ ](https://support.crownpeak.com/hc/en-us/sections/11135345237917-Integration-Guides)via the [HTTP](http://en.wikipedia.org/wiki/HTTP) and [HTTPS](http://en.wikipedia.org/wiki/HTTP_Secure) protocols. Please keep in mind that HTTPS adds an additional 50-100ms of latency to each query. For example, if a HTTP round-trip takes 400ms, then the same round-trip via HTTPS would take 450-500ms.
{% endhint %}

### Compressed responses <a href="#front-endintegrationspecification-compressedresponses" id="front-endintegrationspecification-compressedresponses"></a>

Fredhopper's query API supports [HTTP compression](http://en.wikipedia.org/wiki/HTTP_compression) on the responses that are returned back to you web application. We **strongly advise you to use HTTP compression since it reduces the network traffic by factor 10-15**. In order to test this functionality, you can send a sample query request to the API that includes the required HTTP header for enabling a compressed response. See the example below that uses the wget command (note the HTTP header value in the request):

| `wget --header="Accept-Encoding: gzip"` `--user=<USERNAME> --password=<PASSWORD> https://query.published.live1.fas.eu1.fredhopperservices.com/fredhopper/query?fh_location=//catalog01/en_GB` |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

Compression of the requests that are sent to Fredhopper is not supported on the Query API.

### JSON-format responses <a href="#front-endintegrationspecification-json-formatresponses" id="front-endintegrationspecification-json-formatresponses"></a>

When using the REST endpoint, it is possible to receive the response back in JSON-format rather than an XML-format. The size of the JSON response is approximately 5% smaller than the same response in an XML-format and **we strongly advise to enable JSON responses as per best practices**. In order to test this functionality, you can send a sample query request to the API that includes the required HTTP header for enabling a JSON-format response. See the example below that uses the wget command (note the HTTP header values in the request):

{% code overflow="wrap" %}

```
wget --header="Accept: application/json" --header="Accept-Encoding: gzip" -- user=<USERNAME> --password=<PASSWORD> https:// query.published.live1.fas.eu1.fredhopperservices.com/fredhopper/query?fh_location=// catalog01/en_GB
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://crownpeak.gitbook.io/product-discovery/building-the-front-end-experience-with-fhr/sending-queries.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
