Can I submit search terms wrapped in quotes through your API? (Phrase Queries)

api

#1

Is it possible to send a query request with the search term wrapped in quotes? I am getting an error when trying to do this.

For instance if the user types “foo bar” (with the quotes) into our search box I get: "The remote server returned an error: (400) Bad Request." when calling the Swiftype API.

The query I am sending is something like this:

{
    "auth_token": "xxxxxx",
    "q": ""foo bar "",
    "per_page": "10",
    "page": "1",
    "filters": {
        "page": {
            "type": ["xxxxx", "xxxxx"]
        }
    }
}

This is definitely doable! We refer to these as phrase queries, and they are an important part of the Swiftype search experience for most sites. To successfully submit your search request be sure to escape the double quotes around the query. Here’s an update to your example (note the backslashes):

{
    "auth_token": "xxxxxx",
    "q": "\"foo bar\"",
    "per_page": "10",
    "page": "1",
    "filters": {
        "page": {
            "type": ["xxxxx", "xxxxx"]
        }
    }
}