# Map a website

> Find every address of a website with one call: the links of a page plus the sitemaps from robots.txt or sitemap.xml, filtered to the same site and searchable.

Source: https://docs.virginproxy.com/map/

`POST /v1/map` lists the addresses of a website: the links on the page you give plus everything in the site's sitemaps, each address once, only from the same site. Use it to plan a crawl, to find all product or article pages, or to give an AI agent a table of contents.

## Map a site

**cURL**

```bash
curl https://api.virginproxy.com/v1/map \
  -H "Authorization: Bearer $VP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://www.virginproxy.com/en/",
    "search": "features",
    "limit": 3
  }'
```

**Python**

```python
import os, requests

r = requests.post(
    "https://api.virginproxy.com/v1/map",
    headers={"Authorization": "Bearer " + os.environ["VP_KEY"]},
    json={
        "url": "https://www.virginproxy.com/en/",
        "search": "features",
        "limit": 3,
    },
    timeout=120,
)
data = r.json()
if not r.ok:
    raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["total"], data["truncated"])
print(data["links"])
```

**Node.js**

```javascript
const res = await fetch("https://api.virginproxy.com/v1/map", {
  method: "POST",
  headers: { Authorization: "Bearer " + process.env.VP_KEY, "Content-Type": "application/json" },
  body: JSON.stringify({
    url: "https://www.virginproxy.com/en/",
    search: "features",
    limit: 3,
  }),
  signal: AbortSignal.timeout(120_000),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.code + ": " + data.error.message);
console.log(data.total, data.truncated);
console.log(data.links);
```

**Python SDK**

```pysdk
from virginproxy import VirginProxy  # docs.virginproxy.com/sdk/virginproxy.py

vp = VirginProxy()  # reads VP_KEY
data = vp.call("POST", "/v1/map", {
    "url": "https://www.virginproxy.com/en/",
    "search": "features",
    "limit": 3,
})
print(data)
```

**Node SDK**

```nodesdk
import { VirginProxy } from "./virginproxy.mjs"; // docs.virginproxy.com/sdk/virginproxy.mjs

const vp = new VirginProxy(); // reads VP_KEY
const data = await vp.map({
  url: "https://www.virginproxy.com/en/",
  search: "features",
  limit: 3,
});
console.log(data);
```

**PHP**

```php
<?php
$ch = curl_init("https://api.virginproxy.com/v1/map");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 120,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("VP_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "url" => "https://www.virginproxy.com/en/",
        "search" => "features",
        "limit" => 3,
    ], JSON_UNESCAPED_SLASHES),
]);
$data = json_decode(curl_exec($ch), true);
if (isset($data["error"])) {
    exit($data["error"]["code"] . ": " . $data["error"]["message"] . PHP_EOL);
}
echo $data["total"], " ", $data["truncated"], PHP_EOL;
echo json_encode($data["links"], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), PHP_EOL;
```

**Go**

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"os"
	"time"
)

func main() {
	payload := []byte(`{
  "url": "https://www.virginproxy.com/en/",
  "search": "features",
  "limit": 3
}`)
	req, err := http.NewRequest("POST", "https://api.virginproxy.com/v1/map", bytes.NewReader(payload))
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("VP_KEY"))
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{Timeout: 120 * time.Second}
	res, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()

	var data map[string]any
	if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
		log.Fatal(err)
	}
	if res.StatusCode >= 300 {
		e := data["error"].(map[string]any)
		log.Fatalf("%v: %v", e["code"], e["message"])
	}
	fmt.Println(data["total"], data["truncated"])
	fmt.Println(data["links"])
}
```

POST`/v1/map`

*Response:*

```json
{
  "url": "https://www.virginproxy.com/en/",
  "host": "www.virginproxy.com",
  "links": [
    { "url": "https://www.virginproxy.com/en/features/", "text": "Features", "source": "page" },
    { "url": "https://www.virginproxy.com/en/features/javascript-rendering/", "text": "JavaScript rendering", "source": "page" },
    { "url": "https://www.virginproxy.com/en/features/screenshot-api/", "text": "Screenshot API", "source": "page" }
  ],
  "total": 70,
  "truncated": true,
  "sitemaps": { "read": 1 },
  "requests": [
    { "id": "req_h76MlP6HztFCfnbL5huN", "url": "https://www.virginproxy.com/en/", "status": 200, "credits": 1 },
    { "id": "req_XGP2qcw58HmZ932dai9T", "url": "https://www.virginproxy.com/robots.txt", "status": 200, "credits": 1 },
    { "id": "req_cyoIclUmFy3pkmFRcOpe", "url": "https://www.virginproxy.com/sitemap.xml", "status": 200, "credits": 1 }
  ],
  "cost": { "credits": 3, "credits_used": 43, "credits_included": 1000 }
}
```

## How it works

1. The page is read and its links are collected (with their text).
2. `robots.txt` of the site is read for `Sitemap:` lines. Without any, `/sitemap.xml` is tried.
3. Sitemaps are read, also sitemap indexes and `.gz` files, up to 5 files.
4. Only addresses of the same site are kept (`www.` counts as the same), without `#fragments`, each once – page links first, in page order, then sitemap entries.

`sitemaps.stopped` says why reading sitemaps ended early, if it did: `max_credits reached`, `time limit reached` or after the first 5 files.

## Options

| Field | Default | Meaning |
| --- | --- | --- |
| `url` | required | A page of the site, usually its home page. |
| `sitemap` | `"include"` | `include`: the page's links and the sitemaps. `skip`: only the page. `only`: only the sitemaps (the page is not loaded). |
| `include_subdomains` | `false` | Also keep addresses on subdomains (`blog.example.com` for `example.com`). |
| `search` | – | Keep only addresses (or link texts) that contain this text, case ignored. 1 to 200 characters. |
| `limit` | `1000` | Return at most this many addresses, 1 to 5,000. `total` says how many were found. |
| `render` | `false` | Load the page in a browser first (10 credits or more), for menus built by JavaScript. |
| `browser` | `"chrome"` | Browser profile for the reads. |
| `locale` | `"de-DE"` | Language of the visitor. |
| `session` | – | Session name for all reads. |
| `max_credits` | – | Bound for all reads of this call together, 1 to 1,000. |
| `tag` | – | Your tag; every read is in your request log with it. |
| `robots` | `"ignore"` | `"respect"` leaves out addresses the site's robots.txt disallows, `"report"` keeps them marked with `"disallowed": true`. |

## What it costs

Every page and file read is an ordinary request: it is in your [request log](https://docs.virginproxy.com/account/#list) and costs what any request costs – 1 credit per started MB. A typical map costs 3 credits (page, robots.txt, one sitemap). At most it reads the page, robots.txt and 5 sitemap files of up to 10 credits each. `requests` lists every read with its cost, `cost.credits` is the sum. `max_credits` bounds the whole call.

When the page itself does not answer, the call fails like a request (`timeout`, `target_unreachable` …, not charged). A missing robots.txt or sitemap is no error: they are simply left out.

> **Tip:** The reads follow each other quickly. If your plan allows few requests per second, map waits for your rate between them instead of failing – a map on the Free plan takes a few seconds.

## Next: crawl what you found

Hand the addresses to a [job](https://docs.virginproxy.com/jobs/) to fetch them all, or let a [crawl](https://docs.virginproxy.com/crawl/) find and fetch the pages in one go.
