API Searching

Dexter makes an endpoint available for searching outside of Craft templates. The URL endpoint defaults to https://mysite.com/dexter/search.

You can use GET or POST requests. If you are using POST, the secureSearch setting is enabled by default and will expect a valid CSRF token to be sent as the X-CSRF-Token header value in the request. You will need to acquire the current token and add it to your request. For example:

{
    "index": "test_files",
    "term": "empire",
    "filters": {
        "limit": 6,
        "hybrid": {
          "embedder": "fullText"
        }
    }
}

GET requests do not require a CSRF token. Since you're simply performing a search a GET request is generally accepted, however, if you are using a large filters object, it is recommended to use a POST request. GET requests have the benefit of being sharable URLs, but depending on the complexity of your search filters you may want to consider a POST request. An example GET request will need to have the filters be a valid JSON object that is url encoded. For example:

https://mysite.com/dexter/search?index=test_files&term=empire&filters=%7B%22limit%22%3A6%2C%22hybrid%22%3A%7B%22embedder%22%3A%22fullText%22%7D%7D

Last updated

Was this helpful?