# Recipes

> Complete workflows built from several endpoints: nightly price monitoring with webhooks and CSV export, a site inventory with map and batch, a crawl kept as a file, an AI agent with its own budget.

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

Each recipe combines a few endpoints into a complete workflow, with code you can copy. The figure under each example is about what that call costs.

- [Price monitoring every night](#price-monitoring)
- [Inventory of a website](#site-inventory)
- [Crawl a site and keep it as a file](#crawl-export)
- [An AI agent with its own budget](#agent-mcp)
- [Watch prices every hour, hear only about changes](#price-monitor)

## Price monitoring every night

Read the prices of a list of product pages once a night, get told when the run is done, never pay twice for the same night, and keep the result as a spreadsheet.

1. Start the night's jobOne [job](https://docs.virginproxy.com/jobs/) with every product page and the same [extract rule](https://docs.virginproxy.com/extract/) for all of them (in `request`). The `Idempotency-Key` carries the date: if your scheduler starts twice, or your connection breaks, the second call returns the same job instead of a second run. cURLPythonNode.jsPython SDKNode SDKPHPGoRubyJavaC#`curl https://api.virginproxy.com/v1/jobs \
-H "Authorization: Bearer $VP_KEY" \
-H "Idempotency-Key: prices-2026-11-25" \
-H "Content-Type: application/json" \
-d '{
"requests": [
{
"url": "https://shop.example/product/42"
},
{
"url": "https://shop.example/product/43"
},
{
"url": "https://shop.example/product/44"
}
],
"request": {
"extract": {
"price": {
"selector": "[itemprop=price]",
"attr": "content",
"type": "number"
},
"title": "h1"
}
},
"webhook": {
"url": "https://example.com/hooks/virginproxy",
"events": [
"done"
]
},
"tag": "prices/nightly"
}'``import os, requests

r = requests.post(
"https://api.virginproxy.com/v1/jobs",
headers={"Authorization": "Bearer " + os.environ["VP_KEY"], "Idempotency-Key": "prices-2026-11-25"},
json={
"requests": [
{"url": "https://shop.example/product/42"},
{"url": "https://shop.example/product/43"},
{"url": "https://shop.example/product/44"},
],
"request": {
"extract": {
"price": {
"selector": "[itemprop=price]",
"attr": "content",
"type": "number",
},
"title": "h1",
},
},
"webhook": {
"url": "https://example.com/hooks/virginproxy",
"events": ["done"],
},
"tag": "prices/nightly",
},
timeout=30,
)
data = r.json()
if not r.ok:
raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["id"], data["status"])``const res = await fetch("https://api.virginproxy.com/v1/jobs", {
method: "POST",
headers: { Authorization: "Bearer " + process.env.VP_KEY, "Content-Type": "application/json", "Idempotency-Key": "prices-2026-11-25" },
body: JSON.stringify({
requests: [
{ url: "https://shop.example/product/42" },
{ url: "https://shop.example/product/43" },
{ url: "https://shop.example/product/44" },
],
request: {
extract: {
price: {
selector: "[itemprop=price]",
attr: "content",
type: "number",
},
title: "h1",
},
},
webhook: {
url: "https://example.com/hooks/virginproxy",
events: ["done"],
},
tag: "prices/nightly",
}),
signal: AbortSignal.timeout(30_000),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.code + ": " + data.error.message);
console.log(data.id, data.status);``from virginproxy import VirginProxy # docs.virginproxy.com/sdk/virginproxy.py

vp = VirginProxy() # reads VP_KEY
data = vp.create_job({
"requests": [
{"url": "https://shop.example/product/42"},
{"url": "https://shop.example/product/43"},
{"url": "https://shop.example/product/44"},
],
"request": {
"extract": {
"price": {
"selector": "[itemprop=price]",
"attr": "content",
"type": "number",
},
"title": "h1",
},
},
"webhook": {
"url": "https://example.com/hooks/virginproxy",
"events": ["done"],
},
"tag": "prices/nightly",
})
print(data)``import { VirginProxy } from "./virginproxy.mjs"; // docs.virginproxy.com/sdk/virginproxy.mjs

const vp = new VirginProxy(); // reads VP_KEY
const data = await vp.createJob({
requests: [
{ url: "https://shop.example/product/42" },
{ url: "https://shop.example/product/43" },
{ url: "https://shop.example/product/44" },
],
request: {
extract: {
price: {
selector: "[itemprop=price]",
attr: "content",
type: "number",
},
title: "h1",
},
},
webhook: {
url: "https://example.com/hooks/virginproxy",
events: ["done"],
},
tag: "prices/nightly",
});
console.log(data);``<?php
$ch = curl_init("https://api.virginproxy.com/v1/jobs");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("VP_KEY"),
"Content-Type: application/json",
"Idempotency-Key: prices-2026-11-25",
],
CURLOPT_POSTFIELDS => json_encode([
"requests" => [
["url" => "https://shop.example/product/42"],
["url" => "https://shop.example/product/43"],
["url" => "https://shop.example/product/44"],
],
"request" => [
"extract" => [
"price" => [
"selector" => "[itemprop=price]",
"attr" => "content",
"type" => "number",
],
"title" => "h1",
],
],
"webhook" => [
"url" => "https://example.com/hooks/virginproxy",
"events" => ["done"],
],
"tag" => "prices/nightly",
], 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["id"], " ", $data["status"], PHP_EOL;``` package main

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

func main() {
payload := []byte(`{
"requests": [
{
"url": "https://shop.example/product/42"
},
{
"url": "https://shop.example/product/43"
},
{
"url": "https://shop.example/product/44"
}
],
"request": {
"extract": {
"price": {
"selector": "[itemprop=price]",
"attr": "content",
"type": "number"
},
"title": "h1"
}
},
"webhook": {
"url": "https://example.com/hooks/virginproxy",
"events": [
"done"
]
},
"tag": "prices/nightly"
}`)
req, err := http.NewRequest("POST", "https://api.virginproxy.com/v1/jobs", 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")
req.Header.Set("Idempotency-Key", "prices-2026-11-25")

client := &http.Client{Timeout: 30 * 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["id"], data["status"])
} ```require "json"
require "net/http"

uri = URI("https://api.virginproxy.com/v1/jobs")
req = Net::HTTP::Post.new(uri)
req["Authorization"] = "Bearer " + ENV.fetch("VP_KEY")
req["Content-Type"] = "application/json"
req["Idempotency-Key"] = "prices-2026-11-25"
req.body = JSON.generate({
"requests" => [
{ "url" => "https://shop.example/product/42" },
{ "url" => "https://shop.example/product/43" },
{ "url" => "https://shop.example/product/44" },
],
"request" => {
"extract" => {
"price" => {
"selector" => "[itemprop=price]",
"attr" => "content",
"type" => "number",
},
"title" => "h1",
},
},
"webhook" => {
"url" => "https://example.com/hooks/virginproxy",
"events" => ["done"],
},
"tag" => "prices/nightly",
})

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: 30) { |http| http.request(req) }
data = JSON.parse(res.body)
abort(data["error"]["code"] + ": " + data["error"]["message"]) unless res.is_a?(Net::HTTPSuccess)
puts [data["id"], data["status"]].join(" ")``import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"requests": [
{
"url": "https://shop.example/product/42"
},
{
"url": "https://shop.example/product/43"
},
{
"url": "https://shop.example/product/44"
}
],
"request": {
"extract": {
"price": {
"selector": "[itemprop=price]",
"attr": "content",
"type": "number"
},
"title": "h1"
}
},
"webhook": {
"url": "https://example.com/hooks/virginproxy",
"events": [
"done"
]
},
"tag": "prices/nightly"
}
""";
HttpRequest req = HttpRequest.newBuilder(URI.create("https://api.virginproxy.com/v1/jobs"))
.header("Authorization", "Bearer " + System.getenv("VP_KEY"))
.header("Content-Type", "application/json")
.header("Idempotency-Key", "prices-2026-11-25")
.timeout(Duration.ofSeconds(30))
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
if (res.statusCode() >= 300) {
System.err.println(res.statusCode() + " " + res.body()); // the error object: code, message
System.exit(1);
}
System.out.println(res.body()); // JSON: read it with the JSON library of your choice
}
}``using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("VP_KEY"));
var payload = """
{
"requests": [
{
"url": "https://shop.example/product/42"
},
{
"url": "https://shop.example/product/43"
},
{
"url": "https://shop.example/product/44"
}
],
"request": {
"extract": {
"price": {
"selector": "[itemprop=price]",
"attr": "content",
"type": "number"
},
"title": "h1"
}
},
"webhook": {
"url": "https://example.com/hooks/virginproxy",
"events": [
"done"
]
},
"tag": "prices/nightly"
}
""";
var req = new HttpRequestMessage(HttpMethod.Post, "https://api.virginproxy.com/v1/jobs");
req.Headers.Add("Idempotency-Key", "prices-2026-11-25");
req.Content = new StringContent(payload, Encoding.UTF8, "application/json");
var res = await http.SendAsync(req);
using var data = JsonDocument.Parse(await res.Content.ReadAsStringAsync());
if (!res.IsSuccessStatusCode)
{
var e = data.RootElement.GetProperty("error");
Console.Error.WriteLine(e.GetProperty("code") + ": " + e.GetProperty("message"));
Environment.Exit(1);
}
Console.WriteLine(data.RootElement.GetProperty("id") + " " + data.RootElement.GetProperty("status"));`POST`/v1/jobs`[≈ 3 credits](https://docs.virginproxy.com/billing/#cost)
2. Get told when it is doneThe `done` event arrives as a signed POST at your URL ([job.done](https://docs.virginproxy.com/webhooks/#event-done)). [Check the signature](https://docs.virginproxy.com/webhooks/#verify) – or paste a delivery into the [signature check](https://docs.virginproxy.com/webhooks/#check-signature) while you build it – and answer 200 at once.
3. Download the results as CSVOne row per product; `extracted` is a JSON column with `price` and `title`. Leave out the page bodies to keep the file small: Download as CSV`curl "https://api.virginproxy.com/v1/jobs/job_8fK2pQ7wLz3nVd0sXa4T/export?format=csv&include_body=false" \
-H "Authorization: Bearer $VP_KEY" \
-o prices-2026-11-25.csv` Products that failed (a timeout, a refusal) can be sent once more with [`POST /v1/jobs/{id}/retry`](https://docs.virginproxy.com/jobs/#retry); only those are run again.

More: [Jobs and batches](https://docs.virginproxy.com/jobs/) · [Webhooks](https://docs.virginproxy.com/webhooks/) · [Send again safely](https://docs.virginproxy.com/limits/#idempotency)

## Inventory of a website

Find every address of a site, then read a handful of them right away – for an audit, a migration or to feed a search index.

1. List the addresses[Map](https://docs.virginproxy.com/map/) reads the start page and the sitemaps and returns each address once. `search` keeps only those containing a word: cURLPythonNode.jsPython SDKNode SDKPHPGoRubyJavaC#`curl https://api.virginproxy.com/v1/map \
-H "Authorization: Bearer $VP_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/",
"search": "blog",
"limit": 500
}'``import os, requests

r = requests.post(
"https://api.virginproxy.com/v1/map",
headers={"Authorization": "Bearer " + os.environ["VP_KEY"]},
json={"url": "https://example.com/", "search": "blog", "limit": 500},
timeout=120,
)
data = r.json()
if not r.ok:
raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["total"])
print(data["links"][0]["url"])``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://example.com/", search: "blog", limit: 500 }),
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);
console.log(data.links[0].url);``from virginproxy import VirginProxy # docs.virginproxy.com/sdk/virginproxy.py

vp = VirginProxy() # reads VP_KEY
data = vp.call("POST", "/v1/map", {"url": "https://example.com/", "search": "blog", "limit": 500})
print(data)``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://example.com/", search: "blog", limit: 500 });
console.log(data);``<?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://example.com/",
"search" => "blog",
"limit" => 500,
], 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"], PHP_EOL;
echo json_encode($data["links"][0]["url"], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), PHP_EOL;``` package main

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

func main() {
payload := []byte(`{
"url": "https://example.com/",
"search": "blog",
"limit": 500
}`)
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"])
fmt.Println(data["links"].([]any)[0].(map[string]any)["url"])
} ```require "json"
require "net/http"

uri = URI("https://api.virginproxy.com/v1/map")
req = Net::HTTP::Post.new(uri)
req["Authorization"] = "Bearer " + ENV.fetch("VP_KEY")
req["Content-Type"] = "application/json"
req.body = JSON.generate({
"url" => "https://example.com/",
"search" => "blog",
"limit" => 500,
})

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: 120) { |http| http.request(req) }
data = JSON.parse(res.body)
abort(data["error"]["code"] + ": " + data["error"]["message"]) unless res.is_a?(Net::HTTPSuccess)
puts data["total"]
puts JSON.pretty_generate(data["links"][0]["url"])``import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"url": "https://example.com/",
"search": "blog",
"limit": 500
}
""";
HttpRequest req = HttpRequest.newBuilder(URI.create("https://api.virginproxy.com/v1/map"))
.header("Authorization", "Bearer " + System.getenv("VP_KEY"))
.header("Content-Type", "application/json")
.timeout(Duration.ofSeconds(120))
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
if (res.statusCode() >= 300) {
System.err.println(res.statusCode() + " " + res.body()); // the error object: code, message
System.exit(1);
}
System.out.println(res.body()); // JSON: read it with the JSON library of your choice
}
}``using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(120) };
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("VP_KEY"));
var payload = """
{
"url": "https://example.com/",
"search": "blog",
"limit": 500
}
""";
var req = new HttpRequestMessage(HttpMethod.Post, "https://api.virginproxy.com/v1/map");
req.Content = new StringContent(payload, Encoding.UTF8, "application/json");
var res = await http.SendAsync(req);
using var data = JsonDocument.Parse(await res.Content.ReadAsStringAsync());
if (!res.IsSuccessStatusCode)
{
var e = data.RootElement.GetProperty("error");
Console.Error.WriteLine(e.GetProperty("code") + ": " + e.GetProperty("message"));
Environment.Exit(1);
}
Console.WriteLine(data.RootElement.GetProperty("total"));
Console.WriteLine(data.RootElement.GetProperty("links")[0].GetProperty("url"));`POST`/v1/map`
2. Read a few of them at oncePass the first addresses to a [batch](https://docs.virginproxy.com/jobs/#batch): they run at the same time and the answer comes when all are done. A batch takes up to your plan's batch limit (`requests_per_batch` in [GET /v1/account](https://docs.virginproxy.com/account/#account)); for more addresses, use a job as in the recipe above. cURLPythonNode.jsPython SDKNode SDKPHPGoRubyJavaC#`curl https://api.virginproxy.com/v1/batch \
-H "Authorization: Bearer $VP_KEY" \
-H "Content-Type: application/json" \
-d '{
"urls": [
"https://example.com/blog/first-post",
"https://example.com/blog/second-post"
],
"request": {
"format": "markdown",
"main_content": true
}
}'``import os, requests

r = requests.post(
"https://api.virginproxy.com/v1/batch",
headers={"Authorization": "Bearer " + os.environ["VP_KEY"]},
json={
"urls": [
"https://example.com/blog/first-post",
"https://example.com/blog/second-post",
],
"request": {"format": "markdown", "main_content": True},
},
timeout=120,
)
data = r.json()
if not r.ok:
raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["succeeded"], data["failed"], data["cost"]["credits"])``const res = await fetch("https://api.virginproxy.com/v1/batch", {
method: "POST",
headers: { Authorization: "Bearer " + process.env.VP_KEY, "Content-Type": "application/json" },
body: JSON.stringify({
urls: [
"https://example.com/blog/first-post",
"https://example.com/blog/second-post",
],
request: { format: "markdown", main_content: true },
}),
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.succeeded, data.failed, data.cost.credits);``from virginproxy import VirginProxy # docs.virginproxy.com/sdk/virginproxy.py

vp = VirginProxy() # reads VP_KEY
data = vp.call("POST", "/v1/batch", {
"urls": [
"https://example.com/blog/first-post",
"https://example.com/blog/second-post",
],
"request": {"format": "markdown", "main_content": True},
})
print(data)``import { VirginProxy } from "./virginproxy.mjs"; // docs.virginproxy.com/sdk/virginproxy.mjs

const vp = new VirginProxy(); // reads VP_KEY
const data = await vp.batch({
urls: [
"https://example.com/blog/first-post",
"https://example.com/blog/second-post",
],
request: { format: "markdown", main_content: true },
});
console.log(data);``<?php
$ch = curl_init("https://api.virginproxy.com/v1/batch");
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([
"urls" => [
"https://example.com/blog/first-post",
"https://example.com/blog/second-post",
],
"request" => ["format" => "markdown", "main_content" => true],
], 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["succeeded"], " ", $data["failed"], " ", $data["cost"]["credits"], PHP_EOL;``` package main

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

func main() {
payload := []byte(`{
"urls": [
"https://example.com/blog/first-post",
"https://example.com/blog/second-post"
],
"request": {
"format": "markdown",
"main_content": true
}
}`)
req, err := http.NewRequest("POST", "https://api.virginproxy.com/v1/batch", 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["succeeded"], data["failed"], data["cost"].(map[string]any)["credits"])
} ```require "json"
require "net/http"

uri = URI("https://api.virginproxy.com/v1/batch")
req = Net::HTTP::Post.new(uri)
req["Authorization"] = "Bearer " + ENV.fetch("VP_KEY")
req["Content-Type"] = "application/json"
req.body = JSON.generate({
"urls" => [
"https://example.com/blog/first-post",
"https://example.com/blog/second-post",
],
"request" => { "format" => "markdown", "main_content" => true },
})

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: 120) { |http| http.request(req) }
data = JSON.parse(res.body)
abort(data["error"]["code"] + ": " + data["error"]["message"]) unless res.is_a?(Net::HTTPSuccess)
puts [data["succeeded"], data["failed"], data["cost"]["credits"]].join(" ")``import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"urls": [
"https://example.com/blog/first-post",
"https://example.com/blog/second-post"
],
"request": {
"format": "markdown",
"main_content": true
}
}
""";
HttpRequest req = HttpRequest.newBuilder(URI.create("https://api.virginproxy.com/v1/batch"))
.header("Authorization", "Bearer " + System.getenv("VP_KEY"))
.header("Content-Type", "application/json")
.timeout(Duration.ofSeconds(120))
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
if (res.statusCode() >= 300) {
System.err.println(res.statusCode() + " " + res.body()); // the error object: code, message
System.exit(1);
}
System.out.println(res.body()); // JSON: read it with the JSON library of your choice
}
}``using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(120) };
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("VP_KEY"));
var payload = """
{
"urls": [
"https://example.com/blog/first-post",
"https://example.com/blog/second-post"
],
"request": {
"format": "markdown",
"main_content": true
}
}
""";
var req = new HttpRequestMessage(HttpMethod.Post, "https://api.virginproxy.com/v1/batch");
req.Content = new StringContent(payload, Encoding.UTF8, "application/json");
var res = await http.SendAsync(req);
using var data = JsonDocument.Parse(await res.Content.ReadAsStringAsync());
if (!res.IsSuccessStatusCode)
{
var e = data.RootElement.GetProperty("error");
Console.Error.WriteLine(e.GetProperty("code") + ": " + e.GetProperty("message"));
Environment.Exit(1);
}
Console.WriteLine(data.RootElement.GetProperty("succeeded") + " " + data.RootElement.GetProperty("failed") + " " + data.RootElement.GetProperty("cost").GetProperty("credits"));`POST`/v1/batch`[≈ 2 credits](https://docs.virginproxy.com/billing/#cost)

More: [Map a website](https://docs.virginproxy.com/map/) · [Batches](https://docs.virginproxy.com/jobs/#batch) · [Output formats](https://docs.virginproxy.com/formats/)

## Crawl a site and keep it as a file

Follow the links of a site up to a depth you choose, as Markdown, and download everything as one file when it is done.

1. Start the crawlA [crawl](https://docs.virginproxy.com/crawl/) is a job: it runs in the background, its pages are ordinary requests, and `max_pages` and `max_credits` bound what it can cost. cURLPythonNode.jsPython SDKNode SDKPHPGoRubyJavaC#`curl https://api.virginproxy.com/v1/crawl \
-H "Authorization: Bearer $VP_KEY" \
-H "Idempotency-Key: docs-crawl-2026-11-25" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/",
"max_pages": 50,
"max_depth": 2,
"include_paths": [
"/docs/**"
],
"request": {
"format": "markdown",
"main_content": true
},
"max_credits": 100
}'``import os, requests

r = requests.post(
"https://api.virginproxy.com/v1/crawl",
headers={"Authorization": "Bearer " + os.environ["VP_KEY"], "Idempotency-Key": "docs-crawl-2026-11-25"},
json={
"url": "https://example.com/",
"max_pages": 50,
"max_depth": 2,
"include_paths": ["/docs/**"],
"request": {"format": "markdown", "main_content": True},
"max_credits": 100,
},
timeout=30,
)
data = r.json()
if not r.ok:
raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["id"], data["status"])``const res = await fetch("https://api.virginproxy.com/v1/crawl", {
method: "POST",
headers: { Authorization: "Bearer " + process.env.VP_KEY, "Content-Type": "application/json", "Idempotency-Key": "docs-crawl-2026-11-25" },
body: JSON.stringify({
url: "https://example.com/",
max_pages: 50,
max_depth: 2,
include_paths: ["/docs/**"],
request: { format: "markdown", main_content: true },
max_credits: 100,
}),
signal: AbortSignal.timeout(30_000),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.code + ": " + data.error.message);
console.log(data.id, data.status);``from virginproxy import VirginProxy # docs.virginproxy.com/sdk/virginproxy.py

vp = VirginProxy() # reads VP_KEY
data = vp.call("POST", "/v1/crawl", {
"url": "https://example.com/",
"max_pages": 50,
"max_depth": 2,
"include_paths": ["/docs/**"],
"request": {"format": "markdown", "main_content": True},
"max_credits": 100,
})
print(data)``import { VirginProxy } from "./virginproxy.mjs"; // docs.virginproxy.com/sdk/virginproxy.mjs

const vp = new VirginProxy(); // reads VP_KEY
const data = await vp.crawl({
url: "https://example.com/",
max_pages: 50,
max_depth: 2,
include_paths: ["/docs/**"],
request: { format: "markdown", main_content: true },
max_credits: 100,
});
console.log(data);``<?php
$ch = curl_init("https://api.virginproxy.com/v1/crawl");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("VP_KEY"),
"Content-Type: application/json",
"Idempotency-Key: docs-crawl-2026-11-25",
],
CURLOPT_POSTFIELDS => json_encode([
"url" => "https://example.com/",
"max_pages" => 50,
"max_depth" => 2,
"include_paths" => ["/docs/**"],
"request" => ["format" => "markdown", "main_content" => true],
"max_credits" => 100,
], 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["id"], " ", $data["status"], PHP_EOL;``` package main

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

func main() {
payload := []byte(`{
"url": "https://example.com/",
"max_pages": 50,
"max_depth": 2,
"include_paths": [
"/docs/**"
],
"request": {
"format": "markdown",
"main_content": true
},
"max_credits": 100
}`)
req, err := http.NewRequest("POST", "https://api.virginproxy.com/v1/crawl", 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")
req.Header.Set("Idempotency-Key", "docs-crawl-2026-11-25")

client := &http.Client{Timeout: 30 * 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["id"], data["status"])
} ```require "json"
require "net/http"

uri = URI("https://api.virginproxy.com/v1/crawl")
req = Net::HTTP::Post.new(uri)
req["Authorization"] = "Bearer " + ENV.fetch("VP_KEY")
req["Content-Type"] = "application/json"
req["Idempotency-Key"] = "docs-crawl-2026-11-25"
req.body = JSON.generate({
"url" => "https://example.com/",
"max_pages" => 50,
"max_depth" => 2,
"include_paths" => ["/docs/**"],
"request" => { "format" => "markdown", "main_content" => true },
"max_credits" => 100,
})

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: 30) { |http| http.request(req) }
data = JSON.parse(res.body)
abort(data["error"]["code"] + ": " + data["error"]["message"]) unless res.is_a?(Net::HTTPSuccess)
puts [data["id"], data["status"]].join(" ")``import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"url": "https://example.com/",
"max_pages": 50,
"max_depth": 2,
"include_paths": [
"/docs/**"
],
"request": {
"format": "markdown",
"main_content": true
},
"max_credits": 100
}
""";
HttpRequest req = HttpRequest.newBuilder(URI.create("https://api.virginproxy.com/v1/crawl"))
.header("Authorization", "Bearer " + System.getenv("VP_KEY"))
.header("Content-Type", "application/json")
.header("Idempotency-Key", "docs-crawl-2026-11-25")
.timeout(Duration.ofSeconds(30))
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
if (res.statusCode() >= 300) {
System.err.println(res.statusCode() + " " + res.body()); // the error object: code, message
System.exit(1);
}
System.out.println(res.body()); // JSON: read it with the JSON library of your choice
}
}``using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("VP_KEY"));
var payload = """
{
"url": "https://example.com/",
"max_pages": 50,
"max_depth": 2,
"include_paths": [
"/docs/**"
],
"request": {
"format": "markdown",
"main_content": true
},
"max_credits": 100
}
""";
var req = new HttpRequestMessage(HttpMethod.Post, "https://api.virginproxy.com/v1/crawl");
req.Headers.Add("Idempotency-Key", "docs-crawl-2026-11-25");
req.Content = new StringContent(payload, Encoding.UTF8, "application/json");
var res = await http.SendAsync(req);
using var data = JsonDocument.Parse(await res.Content.ReadAsStringAsync());
if (!res.IsSuccessStatusCode)
{
var e = data.RootElement.GetProperty("error");
Console.Error.WriteLine(e.GetProperty("code") + ": " + e.GetProperty("message"));
Environment.Exit(1);
}
Console.WriteLine(data.RootElement.GetProperty("id") + " " + data.RootElement.GetProperty("status"));`POST`/v1/crawl`
2. Download the pagesAs NDJSON – one page per line with its URL, depth and Markdown – while it runs (what is done so far) or up to 24 hours after it ended: Download as NDJSON`curl "https://api.virginproxy.com/v1/jobs/job_RZ0SqikbW5KDPAbikfrL/export?format=ndjson" \
-H "Authorization: Bearer $VP_KEY" \
-o site.ndjson`

More: [Crawl a website](https://docs.virginproxy.com/crawl/) · [Download all results](https://docs.virginproxy.com/jobs/#export)

## An AI agent with its own budget

Let an agent browse through the MCP server with a key that can only send requests and stops at a sum you choose.

1. Make a key for the agentOnly `requests` (it cannot read your request log or manage keys), a credit limit for the period and a daily limit. Do it under [API keys](https://dash.virginproxy.com/keys), or with a key that has `manage`: cURLPythonNode.jsPython SDKNode SDKPHPGoRubyJavaC#`curl https://api.virginproxy.com/v1/keys \
-H "Authorization: Bearer $VP_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "research-agent",
"scopes": [
"requests"
],
"credit_limit": 2000,
"daily_limit": 200
}'``import os, requests

r = requests.post(
"https://api.virginproxy.com/v1/keys",
headers={"Authorization": "Bearer " + os.environ["VP_KEY"]},
json={
"name": "research-agent",
"scopes": ["requests"],
"credit_limit": 2000,
"daily_limit": 200,
},
timeout=30,
)
data = r.json()
if not r.ok:
raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["key"])``const res = await fetch("https://api.virginproxy.com/v1/keys", {
method: "POST",
headers: { Authorization: "Bearer " + process.env.VP_KEY, "Content-Type": "application/json" },
body: JSON.stringify({
name: "research-agent",
scopes: ["requests"],
credit_limit: 2000,
daily_limit: 200,
}),
signal: AbortSignal.timeout(30_000),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.code + ": " + data.error.message);
console.log(data.key);``from virginproxy import VirginProxy # docs.virginproxy.com/sdk/virginproxy.py

vp = VirginProxy() # reads VP_KEY
data = vp.call("POST", "/v1/keys", {
"name": "research-agent",
"scopes": ["requests"],
"credit_limit": 2000,
"daily_limit": 200,
})
print(data)``import { VirginProxy } from "./virginproxy.mjs"; // docs.virginproxy.com/sdk/virginproxy.mjs

const vp = new VirginProxy(); // reads VP_KEY
const data = await vp.call("POST", "/v1/keys", { body: {
name: "research-agent",
scopes: ["requests"],
credit_limit: 2000,
daily_limit: 200,
} });
console.log(data);``<?php
$ch = curl_init("https://api.virginproxy.com/v1/keys");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("VP_KEY"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"name" => "research-agent",
"scopes" => ["requests"],
"credit_limit" => 2000,
"daily_limit" => 200,
], 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["key"], PHP_EOL;``` package main

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

func main() {
payload := []byte(`{
"name": "research-agent",
"scopes": [
"requests"
],
"credit_limit": 2000,
"daily_limit": 200
}`)
req, err := http.NewRequest("POST", "https://api.virginproxy.com/v1/keys", 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: 30 * 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["key"])
} ```require "json"
require "net/http"

uri = URI("https://api.virginproxy.com/v1/keys")
req = Net::HTTP::Post.new(uri)
req["Authorization"] = "Bearer " + ENV.fetch("VP_KEY")
req["Content-Type"] = "application/json"
req.body = JSON.generate({
"name" => "research-agent",
"scopes" => ["requests"],
"credit_limit" => 2000,
"daily_limit" => 200,
})

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: 30) { |http| http.request(req) }
data = JSON.parse(res.body)
abort(data["error"]["code"] + ": " + data["error"]["message"]) unless res.is_a?(Net::HTTPSuccess)
puts data["key"]``import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"name": "research-agent",
"scopes": [
"requests"
],
"credit_limit": 2000,
"daily_limit": 200
}
""";
HttpRequest req = HttpRequest.newBuilder(URI.create("https://api.virginproxy.com/v1/keys"))
.header("Authorization", "Bearer " + System.getenv("VP_KEY"))
.header("Content-Type", "application/json")
.timeout(Duration.ofSeconds(30))
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
if (res.statusCode() >= 300) {
System.err.println(res.statusCode() + " " + res.body()); // the error object: code, message
System.exit(1);
}
System.out.println(res.body()); // JSON: read it with the JSON library of your choice
}
}``using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("VP_KEY"));
var payload = """
{
"name": "research-agent",
"scopes": [
"requests"
],
"credit_limit": 2000,
"daily_limit": 200
}
""";
var req = new HttpRequestMessage(HttpMethod.Post, "https://api.virginproxy.com/v1/keys");
req.Content = new StringContent(payload, Encoding.UTF8, "application/json");
var res = await http.SendAsync(req);
using var data = JsonDocument.Parse(await res.Content.ReadAsStringAsync());
if (!res.IsSuccessStatusCode)
{
var e = data.RootElement.GetProperty("error");
Console.Error.WriteLine(e.GetProperty("code") + ": " + e.GetProperty("message"));
Environment.Exit(1);
}
Console.WriteLine(data.RootElement.GetProperty("key"));`POST`/v1/keys`
2. Connect the agentPut the new key into your MCP client's configuration: MCP client configuration (JSON)`{
"mcpServers": {
"virginproxy": {
"url": "https://api.virginproxy.com/mcp",
"headers": {
"Authorization": "Bearer vp_live_…"
}
}
}
}` When the agent reaches a limit, its calls end with `key_limit_reached` or `daily_limit_reached` (402) and nothing more is charged; your other keys go on. Use a [test key](https://docs.virginproxy.com/test-mode/) while you build the agent: same tools, sample answers, never charged.

More: [AI agents and LLM tools](https://docs.virginproxy.com/ai-agents/) · [Key permissions](https://docs.virginproxy.com/security/#scopes) · [Daily caps](https://docs.virginproxy.com/security/#daily-cap)

## Watch prices every hour, hear only about changes

Save how to read a product page once, let a schedule read your product list every hour with a cost cap, and get a webhook only for pages whose price changed.

1. Save how to read the pageA [preset](https://docs.virginproxy.com/automation/#presets) holds the render and extraction options; requests and schedules use it by name. cURLPythonNode.jsPython SDKNode SDKPHPGoRubyJavaC#`curl https://api.virginproxy.com/v1/presets \
-H "Authorization: Bearer $VP_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "shop-product",
"request": {
"render": {
"wait_for": ".price"
},
"extract": {
"price": {
"selector": ".price",
"type": "number"
}
}
}
}'``import os, requests

r = requests.post(
"https://api.virginproxy.com/v1/presets",
headers={"Authorization": "Bearer " + os.environ["VP_KEY"]},
json={
"name": "shop-product",
"request": {
"render": {"wait_for": ".price"},
"extract": {"price": {"selector": ".price", "type": "number"}},
},
},
timeout=30,
)
data = r.json()
if not r.ok:
raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["status"], data["cost"]["credits"])``const res = await fetch("https://api.virginproxy.com/v1/presets", {
method: "POST",
headers: { Authorization: "Bearer " + process.env.VP_KEY, "Content-Type": "application/json" },
body: JSON.stringify({
name: "shop-product",
request: {
render: { wait_for: ".price" },
extract: { price: { selector: ".price", type: "number" } },
},
}),
signal: AbortSignal.timeout(30_000),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.code + ": " + data.error.message);
console.log(data.status, data.cost.credits);``from virginproxy import VirginProxy # docs.virginproxy.com/sdk/virginproxy.py

vp = VirginProxy() # reads VP_KEY
data = vp.call("POST", "/v1/presets", {
"name": "shop-product",
"request": {
"render": {"wait_for": ".price"},
"extract": {"price": {"selector": ".price", "type": "number"}},
},
})
print(data)``import { VirginProxy } from "./virginproxy.mjs"; // docs.virginproxy.com/sdk/virginproxy.mjs

const vp = new VirginProxy(); // reads VP_KEY
const data = await vp.call("POST", "/v1/presets", { body: {
name: "shop-product",
request: {
render: { wait_for: ".price" },
extract: { price: { selector: ".price", type: "number" } },
},
} });
console.log(data);``<?php
$ch = curl_init("https://api.virginproxy.com/v1/presets");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("VP_KEY"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"name" => "shop-product",
"request" => [
"render" => ["wait_for" => ".price"],
"extract" => ["price" => ["selector" => ".price", "type" => "number"]],
],
], 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["status"], " ", $data["cost"]["credits"], PHP_EOL;``` package main

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

func main() {
payload := []byte(`{
"name": "shop-product",
"request": {
"render": {
"wait_for": ".price"
},
"extract": {
"price": {
"selector": ".price",
"type": "number"
}
}
}
}`)
req, err := http.NewRequest("POST", "https://api.virginproxy.com/v1/presets", 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: 30 * 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["status"], data["cost"].(map[string]any)["credits"])
} ```require "json"
require "net/http"

uri = URI("https://api.virginproxy.com/v1/presets")
req = Net::HTTP::Post.new(uri)
req["Authorization"] = "Bearer " + ENV.fetch("VP_KEY")
req["Content-Type"] = "application/json"
req.body = JSON.generate({
"name" => "shop-product",
"request" => {
"render" => { "wait_for" => ".price" },
"extract" => { "price" => { "selector" => ".price", "type" => "number" } },
},
})

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: 30) { |http| http.request(req) }
data = JSON.parse(res.body)
abort(data["error"]["code"] + ": " + data["error"]["message"]) unless res.is_a?(Net::HTTPSuccess)
puts [data["status"], data["cost"]["credits"]].join(" ")``import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"name": "shop-product",
"request": {
"render": {
"wait_for": ".price"
},
"extract": {
"price": {
"selector": ".price",
"type": "number"
}
}
}
}
""";
HttpRequest req = HttpRequest.newBuilder(URI.create("https://api.virginproxy.com/v1/presets"))
.header("Authorization", "Bearer " + System.getenv("VP_KEY"))
.header("Content-Type", "application/json")
.timeout(Duration.ofSeconds(30))
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
if (res.statusCode() >= 300) {
System.err.println(res.statusCode() + " " + res.body()); // the error object: code, message
System.exit(1);
}
System.out.println(res.body()); // JSON: read it with the JSON library of your choice
}
}``using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("VP_KEY"));
var payload = """
{
"name": "shop-product",
"request": {
"render": {
"wait_for": ".price"
},
"extract": {
"price": {
"selector": ".price",
"type": "number"
}
}
}
}
""";
var req = new HttpRequestMessage(HttpMethod.Post, "https://api.virginproxy.com/v1/presets");
req.Content = new StringContent(payload, Encoding.UTF8, "application/json");
var res = await http.SendAsync(req);
using var data = JsonDocument.Parse(await res.Content.ReadAsStringAsync());
if (!res.IsSuccessStatusCode)
{
var e = data.RootElement.GetProperty("error");
Console.Error.WriteLine(e.GetProperty("code") + ": " + e.GetProperty("message"));
Environment.Exit(1);
}
Console.WriteLine(data.RootElement.GetProperty("status") + " " + data.RootElement.GetProperty("cost").GetProperty("credits"));`POST`/v1/presets`
2. Schedule the listEvery hour, at most 200 credits per run. `track_changes` compares what was read with the last run; `item.changed` sends only the pages that changed. cURLPythonNode.jsPython SDKNode SDKPHPGoRubyJavaC#`curl https://api.virginproxy.com/v1/schedules \
-H "Authorization: Bearer $VP_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Prices",
"every": "1h",
"max_credits": 200,
"job": {
"urls": [
"https://shop.example/p/1",
"https://shop.example/p/2"
],
"defaults": {
"preset": "shop-product",
"track_changes": {
"on": "extracted"
}
},
"webhook": {
"url": "https://your-server.example/hooks/virginproxy",
"events": [
"item.changed"
]
}
}
}'``import os, requests

r = requests.post(
"https://api.virginproxy.com/v1/schedules",
headers={"Authorization": "Bearer " + os.environ["VP_KEY"]},
json={
"name": "Prices",
"every": "1h",
"max_credits": 200,
"job": {
"urls": ["https://shop.example/p/1", "https://shop.example/p/2"],
"defaults": {"preset": "shop-product", "track_changes": {"on": "extracted"}},
"webhook": {
"url": "https://your-server.example/hooks/virginproxy",
"events": ["item.changed"],
},
},
},
timeout=30,
)
data = r.json()
if not r.ok:
raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["status"], data["cost"]["credits"])``const res = await fetch("https://api.virginproxy.com/v1/schedules", {
method: "POST",
headers: { Authorization: "Bearer " + process.env.VP_KEY, "Content-Type": "application/json" },
body: JSON.stringify({
name: "Prices",
every: "1h",
max_credits: 200,
job: {
urls: ["https://shop.example/p/1", "https://shop.example/p/2"],
defaults: { preset: "shop-product", track_changes: { on: "extracted" } },
webhook: {
url: "https://your-server.example/hooks/virginproxy",
events: ["item.changed"],
},
},
}),
signal: AbortSignal.timeout(30_000),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.code + ": " + data.error.message);
console.log(data.status, data.cost.credits);``from virginproxy import VirginProxy # docs.virginproxy.com/sdk/virginproxy.py

vp = VirginProxy() # reads VP_KEY
data = vp.create_schedule({
"name": "Prices",
"every": "1h",
"max_credits": 200,
"job": {
"urls": ["https://shop.example/p/1", "https://shop.example/p/2"],
"defaults": {"preset": "shop-product", "track_changes": {"on": "extracted"}},
"webhook": {
"url": "https://your-server.example/hooks/virginproxy",
"events": ["item.changed"],
},
},
})
print(data)``import { VirginProxy } from "./virginproxy.mjs"; // docs.virginproxy.com/sdk/virginproxy.mjs

const vp = new VirginProxy(); // reads VP_KEY
const data = await vp.createSchedule({
name: "Prices",
every: "1h",
max_credits: 200,
job: {
urls: ["https://shop.example/p/1", "https://shop.example/p/2"],
defaults: { preset: "shop-product", track_changes: { on: "extracted" } },
webhook: {
url: "https://your-server.example/hooks/virginproxy",
events: ["item.changed"],
},
},
});
console.log(data);``<?php
$ch = curl_init("https://api.virginproxy.com/v1/schedules");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("VP_KEY"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"name" => "Prices",
"every" => "1h",
"max_credits" => 200,
"job" => [
"urls" => ["https://shop.example/p/1", "https://shop.example/p/2"],
"defaults" => [
"preset" => "shop-product",
"track_changes" => ["on" => "extracted"],
],
"webhook" => [
"url" => "https://your-server.example/hooks/virginproxy",
"events" => ["item.changed"],
],
],
], 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["status"], " ", $data["cost"]["credits"], PHP_EOL;``` package main

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

func main() {
payload := []byte(`{
"name": "Prices",
"every": "1h",
"max_credits": 200,
"job": {
"urls": [
"https://shop.example/p/1",
"https://shop.example/p/2"
],
"defaults": {
"preset": "shop-product",
"track_changes": {
"on": "extracted"
}
},
"webhook": {
"url": "https://your-server.example/hooks/virginproxy",
"events": [
"item.changed"
]
}
}
}`)
req, err := http.NewRequest("POST", "https://api.virginproxy.com/v1/schedules", 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: 30 * 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["status"], data["cost"].(map[string]any)["credits"])
} ```require "json"
require "net/http"

uri = URI("https://api.virginproxy.com/v1/schedules")
req = Net::HTTP::Post.new(uri)
req["Authorization"] = "Bearer " + ENV.fetch("VP_KEY")
req["Content-Type"] = "application/json"
req.body = JSON.generate({
"name" => "Prices",
"every" => "1h",
"max_credits" => 200,
"job" => {
"urls" => ["https://shop.example/p/1", "https://shop.example/p/2"],
"defaults" => {
"preset" => "shop-product",
"track_changes" => { "on" => "extracted" },
},
"webhook" => {
"url" => "https://your-server.example/hooks/virginproxy",
"events" => ["item.changed"],
},
},
})

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: 30) { |http| http.request(req) }
data = JSON.parse(res.body)
abort(data["error"]["code"] + ": " + data["error"]["message"]) unless res.is_a?(Net::HTTPSuccess)
puts [data["status"], data["cost"]["credits"]].join(" ")``import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"name": "Prices",
"every": "1h",
"max_credits": 200,
"job": {
"urls": [
"https://shop.example/p/1",
"https://shop.example/p/2"
],
"defaults": {
"preset": "shop-product",
"track_changes": {
"on": "extracted"
}
},
"webhook": {
"url": "https://your-server.example/hooks/virginproxy",
"events": [
"item.changed"
]
}
}
}
""";
HttpRequest req = HttpRequest.newBuilder(URI.create("https://api.virginproxy.com/v1/schedules"))
.header("Authorization", "Bearer " + System.getenv("VP_KEY"))
.header("Content-Type", "application/json")
.timeout(Duration.ofSeconds(30))
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
if (res.statusCode() >= 300) {
System.err.println(res.statusCode() + " " + res.body()); // the error object: code, message
System.exit(1);
}
System.out.println(res.body()); // JSON: read it with the JSON library of your choice
}
}``using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("VP_KEY"));
var payload = """
{
"name": "Prices",
"every": "1h",
"max_credits": 200,
"job": {
"urls": [
"https://shop.example/p/1",
"https://shop.example/p/2"
],
"defaults": {
"preset": "shop-product",
"track_changes": {
"on": "extracted"
}
},
"webhook": {
"url": "https://your-server.example/hooks/virginproxy",
"events": [
"item.changed"
]
}
}
}
""";
var req = new HttpRequestMessage(HttpMethod.Post, "https://api.virginproxy.com/v1/schedules");
req.Content = new StringContent(payload, Encoding.UTF8, "application/json");
var res = await http.SendAsync(req);
using var data = JsonDocument.Parse(await res.Content.ReadAsStringAsync());
if (!res.IsSuccessStatusCode)
{
var e = data.RootElement.GetProperty("error");
Console.Error.WriteLine(e.GetProperty("code") + ": " + e.GetProperty("message"));
Environment.Exit(1);
}
Console.WriteLine(data.RootElement.GetProperty("status") + " " + data.RootElement.GetProperty("cost").GetProperty("credits"));`POST`/v1/schedules`
3. Read the changeEach webhook carries the answer with `change.status` `"changed"`, the new `extracted.price` and the request it was compared with. The schedule pauses itself (with a notice) when your credits run out.

More: [Cache, change tracking, presets and schedules](https://docs.virginproxy.com/automation/) · [Webhooks](https://docs.virginproxy.com/webhooks/)
