Skip to main content
Returns a single best-match suggestion for a partial search term against either the marca (make) or modelo (model) field. Used to power autocomplete inputs in the catalog search UI. Endpoint: CATALOG service Action: getSuggestion

Request

action
string
required
Must be "getSuggestion".
payload.term
string
required
The partial search term entered by the user.
payload.field
string
required
The field to search against. Must be either "marca" or "modelo".

Response

status
string
required
Always "success" on success.
suggestion
string | null
The best-matching suggestion string, or null if no match was found for the given term.

Example

const CATALOG_ENDPOINT = 'https://script.google.com/macros/s/AKfycbxenVjZe9C8-0RiYKLxpGfQtobRzydBke44IM4NdNNjh5VRdlB91Ce9dWvQ2xnDFXk0/exec';

async function fetchSuggestion(term, field) {
  const response = await fetch(CATALOG_ENDPOINT, {
    method: 'POST',
    headers: { 'Content-Type': 'text/plain' },
    body: JSON.stringify({
      action: 'getSuggestion',
      payload: { term, field }
    }),
    redirect: 'follow'
  });

  const result = await response.json();
  if (result.status === 'success') {
    return result.suggestion; // e.g., "Toyota" or null
  }
  return null;
}

// Usage in a search input handler
const suggestion = await fetchSuggestion('Toy', 'marca');
if (suggestion) {
  showAutocomplete(suggestion); // Display "Toyota" as the suggestion
}

Build docs developers (and LLMs) love