# Map guides

The jobs Map is built for, each as the requests that do it.

## Find the docs of a site, then read them

Map chooses the pages. [Extract](https://millionshort.com/docs/extract) reads them.

1. List the documentation section:

```bash
curl https://api.millionshort.com/v1/map \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.org/docs", "include": ["^/docs/"], "limit": 200 }'
```

```python
import os

import requests

r = requests.post(
    "https://api.millionshort.com/v1/map",
    headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"]},
    json={
        "url": "https://example.org/docs",
        "include": [
            "^/docs/"
        ],
        "limit": 200
    },
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

```ts
const res = await fetch('https://api.millionshort.com/v1/map', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "url": "https://example.org/docs",
    "include": [
      "^/docs/"
    ],
    "limit": 200
  }),
});
if (!res.ok) throw new Error(`POST /v1/map failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

2. Choose the URLs worth reading, by address and by `title`, and by `page_type` where our index knows the page. Send up to 20 of them to Extract, or more as a [batch](https://millionshort.com/docs/extract/batch):

```bash
curl https://api.millionshort.com/v1/extract \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "urls": ["https://example.org/docs/start", "https://example.org/docs/webhooks"],
    "mode": "live"
  }'
```

```python
import os

import requests

r = requests.post(
    "https://api.millionshort.com/v1/extract",
    headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"]},
    json={
        "urls": [
            "https://example.org/docs/start",
            "https://example.org/docs/webhooks"
        ],
        "mode": "live"
    },
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

```ts
const res = await fetch('https://api.millionshort.com/v1/extract', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "urls": [
      "https://example.org/docs/start",
      "https://example.org/docs/webhooks"
    ],
    "mode": "live"
  }),
});
if (!res.ok) throw new Error(`POST /v1/extract failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

When you want every page of the section and do not need to choose, a [crawl](https://millionshort.com/docs/crawl) with the same `include` does both steps as one job.

## Search inside a site

An agent that needs one page of a site, such as the pricing page or the changelog, should not read the whole list. Send the words:

```bash
curl https://api.millionshort.com/v1/map \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.org/", "search": "refund policy", "limit": 10 }'
```

```python
import os

import requests

r = requests.post(
    "https://api.millionshort.com/v1/map",
    headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"]},
    json={
        "url": "https://example.org/",
        "search": "refund policy",
        "limit": 10
    },
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

```ts
const res = await fetch('https://api.millionshort.com/v1/map', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "url": "https://example.org/",
    "search": "refund policy",
    "limit": 10
  }),
});
if (!res.ok) throw new Error(`POST /v1/map failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

The first URLs are the pages our index finds for those words in the text of the page. A page can match without the words in its address. After them come the URLs whose address or title has every word. A small `limit` keeps the call at 1 credit.

A line for your agent's instructions: "To find one page of a known site, call `map` with the site's address as `url`, what you are looking for as `search`, and a `limit` of 10."

## Which sources to ask for

All three are asked by default, and that is right for most calls. Choose when you know more:

| You want | Ask for | Why |
|---|---|---|
| The fullest list | all three | Each source knows pages the others do not |
| No page of the site requested | `["index"]` | Our index answers. The site is asked for its robots.txt only, so that a site closed to our bot stays closed. You get up to 50 URLs, with titles and labels |
| Only what the site itself publishes | `["sitemap"]` | The site's own list, with its dates |
| What a visitor of one page can reach | `["links"]` | The page and its links, nothing else |

- A sitemap can be out of date or incomplete. A page that nothing links to and no sitemap names is found only when our index holds it.
- The `index` source is not a full list of the site. It is the pages we hold, at most 50 a call, and with `search` the ones that match.
- `last_modified` comes from the sitemap and is the site's own claim.

## What `truncated` means

`summary.truncated` is `true` in two cases:

- **`limit` cut the list.** `summary.found` is larger than `summary.returned`. Raise `limit`, up to 5,000.
- **The sitemaps were not read to the end.** One call reads at most 12 sitemap files and 50,000 URLs, in 15 seconds. A very large site has more than that.

For a very large site, map one section at a time: give the section's address as `url` and its path as `include`. When `limit` cut the list, `search` and `include` do more for you than a larger `limit`. When the sitemaps were not read to the end, they do not help: patterns are applied to what was read, and the files are read from the start each time. The `links` and `index` sources still answer for the section you named.

## Subdomains

By default Map lists the host you named, with or without `www.`. With `include_subdomains: true` it also lists other hosts of the same site, such as `docs.example.org` when you asked about `example.org`. It never lists another site.

## Staying polite

Map makes few requests to a site, and they follow the rules every fetch of ours follows: our declared identity, robots.txt, and the pace a site should be asked at. A site whose robots.txt closes it to our bot answers `403 ROBOTS_DISALLOWED`. There is nothing to work around, and no option to try. [Errors](https://millionshort.com/docs/map/errors) has the rest.
