Skip to content
WP EngineDocumentation

Getting Started

This tutorial will walk you through authenticating with the Smart Search GraphQL API and making your first search request.

This tutorial assumes you have a Smart Search AI instance set up and running. If you haven’t done so already, please follow the Smart Search AI Setup Guide to create your instance.

All API requests must be authenticated by sending a key (a.k.a. “Token”) in the Authorization header as a Bearer token.

Authorization: Bearer {your-api-key}

Find your credentials in the WP Engine User Portal, and save them securely.

  1. Go to my.wpengine.com/products/smart_search
  2. Open the 3-dot menu for your site
  3. Select, “Show Credentials”
  4. Save, “URL” - This is the URL you will use to send your GraphQL requests.
  5. Save, “Access Token” - A private token used to authenticate your requests.

You should now have saved info that looks like this:

Credential Example Value
GraphQL Endpoint https://{site_slug}-{short_id}-atlassearch-{unique_id}-uc.a.run.app/graphql
Access Token 00000000-0000-4000-8000-000000000000

You can make requests to the GraphQL endpoint using any HTTP client or dedicated GraphQL client.

This is an example of a basic find query using curl from the terminal of your choice.

Replace <your-smart-search-url> with your unique GraphQL endpoint and <your-access-token> with your access token.

Terminal window
# This request performs a simple search for "hello world" and will return the total number of matching documents.
$ curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <your-access-token>" \
--data '{ "query": "query { find(query: \"hello world\") { total } }" }' \
<your-smart-search-url>
// The response will look like this:
{
"data": {
"find": {
"total": 123
}
}
}

You can also send Smart Search GraphQL requests directly from your application code.

Use this example with Node.js v18+ (built-in fetch) or modern browser environments.

const GQL_ENDPOINT = '{your-smart-search-url}';
const API_KEY = '{your-api-key}';
async function search(queryText) {
const response = await fetch(GQL_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${API_KEY}`,
},
body: JSON.stringify({
query: `
query FindQuery($query: String!) {
find(query: $query) {
total
documents {
id
data
}
}
}
`,
variables: {
query: queryText,
},
}),
});
if (!response.ok) {
throw new Error(`Request failed with status ${response.status}`);
}
const result = await response.json();
console.log(JSON.stringify(result, null, 2));
}
search('hello world').catch(console.error);

Now that you know how to authenticate and make a basic request, you can explore the full capabilities of the API. For a complete guide to all available parameters, operators, and advanced features, please see the individual API pages.

Last updated: