# How to search medications by name via API

Build Brazilian medication name search with filters, pagination, UUID-based details and empty-result handling.

Canonical: https://iabula.com/docs/en/guides/buscar-medicamento-por-nome

## From a search field to a record

For a catalog interface, send user text as q to Search and present the returned list. Substring search helps explore records related to the text; it does not prove the first row is the correct identity. Let users inspect dosage form and evidence before choosing a record.

```javascript
// Run on your server. Keep the API key out of browser bundles.
const url = new URL("/v1/medications/search", process.env.IABULA_API_BASE);
url.search = new URLSearchParams({ q: "dipirona", limit: "20" });
const response = await fetch(url, {
  headers: { "X-API-Key": process.env.IABULA_API_KEY },
});
const page = await response.json();
if (!response.ok) throw new Error(`${response.status}: ${page.code}`);
console.log(page.data, page.next_cursor);
```

## Do not mix pages from different queries

When the searched name changes, discard next_cursor and previous results. Preserve filters on the next page and treat the cursor as opaque. In an autocomplete UI, bound the input size, debounce changes and cancel stale client requests.

## Details and empty results

Use a returned UUID in GET /v1/medications/{id}. Handle null fields and empty lists without guessing missing facts. If data is empty, explain that the query found no records in current coverage; do not conclude the product does not exist or lacks regulatory registration.

- [Search parameters](https://iabula.com/docs/en/medications)
- [When to use Resolve](https://iabula.com/docs/en/resolve)

## Resources

- [OpenAPI JSON](https://iabula.com/openapi.json)
- [Swagger](https://iabula.com/docs/swagger)
- [Documentation index](https://iabula.com/llms.txt)
