# Delivery to your own storage

> Let jobs, crawls and schedules write their results into your own S3-compatible bucket – AWS S3, Cloudflare R2, Google Cloud Storage, MinIO and more – as NDJSON, JSON or CSV.

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

Add your bucket once as a **storage destination**, then give a job, crawl or schedule a `delivery`: when it ends, its results are written there as one file. No download script, no 24-hour window.

## Add a destination

**cURL**

```bash
curl https://api.virginproxy.com/v1/destinations \
  -H "Authorization: Bearer $VP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Results",
    "type": "s3",
    "endpoint": "https://<account-id>.r2.cloudflarestorage.com",
    "region": "auto",
    "bucket": "scrapes",
    "prefix": "virginproxy/",
    "access_key_id": "<access key>",
    "secret_access_key": "<secret>"
  }'
```

**Python**

```python
import os, requests

r = requests.post(
    "https://api.virginproxy.com/v1/destinations",
    headers={"Authorization": "Bearer " + os.environ["VP_KEY"]},
    json={
        "name": "Results",
        "type": "s3",
        "endpoint": "https://<account-id>.r2.cloudflarestorage.com",
        "region": "auto",
        "bucket": "scrapes",
        "prefix": "virginproxy/",
        "access_key_id": "<access key>",
        "secret_access_key": "<secret>",
    },
    timeout=30,
)
data = r.json()
if not r.ok:
    raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["status"], data["cost"]["credits"])
```

**Node.js**

```javascript
const res = await fetch("https://api.virginproxy.com/v1/destinations", {
  method: "POST",
  headers: { Authorization: "Bearer " + process.env.VP_KEY, "Content-Type": "application/json" },
  body: JSON.stringify({
    name: "Results",
    type: "s3",
    endpoint: "https://<account-id>.r2.cloudflarestorage.com",
    region: "auto",
    bucket: "scrapes",
    prefix: "virginproxy/",
    access_key_id: "<access key>",
    secret_access_key: "<secret>",
  }),
  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);
```

**Python SDK**

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

vp = VirginProxy()  # reads VP_KEY
data = vp.call("POST", "/v1/destinations", {
    "name": "Results",
    "type": "s3",
    "endpoint": "https://<account-id>.r2.cloudflarestorage.com",
    "region": "auto",
    "bucket": "scrapes",
    "prefix": "virginproxy/",
    "access_key_id": "<access key>",
    "secret_access_key": "<secret>",
})
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.call("POST", "/v1/destinations", { body: {
  name: "Results",
  type: "s3",
  endpoint: "https://<account-id>.r2.cloudflarestorage.com",
  region: "auto",
  bucket: "scrapes",
  prefix: "virginproxy/",
  access_key_id: "<access key>",
  secret_access_key: "<secret>",
} });
console.log(data);
```

**PHP**

```php
<?php
$ch = curl_init("https://api.virginproxy.com/v1/destinations");
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" => "Results",
        "type" => "s3",
        "endpoint" => "https://<account-id>.r2.cloudflarestorage.com",
        "region" => "auto",
        "bucket" => "scrapes",
        "prefix" => "virginproxy/",
        "access_key_id" => "<access key>",
        "secret_access_key" => "<secret>",
    ], 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;
```

**Go**

```go
package main

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

func main() {
	payload := []byte(`{
  "name": "Results",
  "type": "s3",
  "endpoint": "https://<account-id>.r2.cloudflarestorage.com",
  "region": "auto",
  "bucket": "scrapes",
  "prefix": "virginproxy/",
  "access_key_id": "<access key>",
  "secret_access_key": "<secret>"
}`)
	req, err := http.NewRequest("POST", "https://api.virginproxy.com/v1/destinations", 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"])
}
```

POST`/v1/destinations`

Any S3-compatible service works: AWS S3 (leave out `endpoint`, give the `region`), Cloudflare R2 (`region` `auto`), Google Cloud Storage in interoperability mode (`https://storage.googleapis.com`), MinIO, Wasabi, Backblaze B2 and others. Services other than AWS are addressed as `endpoint/bucket/key`; set `"path_style": false` if yours wants `bucket.endpoint/key`.

The secret key is stored encrypted and never shown again – not in the API, not in the dashboard. Give the key only the right to write objects (PutObject) into this bucket or prefix. Up to 10 destinations; making and deleting them needs the `manage` [scope](https://docs.virginproxy.com/security/#scopes).

## Test it

`POST /v1/destinations/{id}/test` writes `virginproxy-test.txt` into the prefix and answers `{"ok": true}` – or the storage service's own error, for example `HTTP 403 AccessDenied: Access Denied`. The dashboard has the same button under Settings › Storage.

## Deliver a job

**cURL**

```bash
curl https://api.virginproxy.com/v1/jobs \
  -H "Authorization: Bearer $VP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "urls": [
      "https://shop.example/p/1",
      "https://shop.example/p/2"
    ],
    "defaults": {
      "auto_extract": "product"
    },
    "delivery": {
      "destination": "dst_9Lk2Vb7Qx0Pm3Rn5Tz8W",
      "format": "ndjson",
      "path": "{date}/{job_id}.ndjson"
    }
  }'
```

**Python**

```python
import os, requests

r = requests.post(
    "https://api.virginproxy.com/v1/jobs",
    headers={"Authorization": "Bearer " + os.environ["VP_KEY"]},
    json={
        "urls": ["https://shop.example/p/1", "https://shop.example/p/2"],
        "defaults": {"auto_extract": "product"},
        "delivery": {
            "destination": "dst_9Lk2Vb7Qx0Pm3Rn5Tz8W",
            "format": "ndjson",
            "path": "{date}/{job_id}.ndjson",
        },
    },
    timeout=30,
)
data = r.json()
if not r.ok:
    raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["status"], data["cost"]["credits"])
```

**Node.js**

```javascript
const res = await fetch("https://api.virginproxy.com/v1/jobs", {
  method: "POST",
  headers: { Authorization: "Bearer " + process.env.VP_KEY, "Content-Type": "application/json" },
  body: JSON.stringify({
    urls: ["https://shop.example/p/1", "https://shop.example/p/2"],
    defaults: { auto_extract: "product" },
    delivery: {
      destination: "dst_9Lk2Vb7Qx0Pm3Rn5Tz8W",
      format: "ndjson",
      path: "{date}/{job_id}.ndjson",
    },
  }),
  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);
```

**Python SDK**

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

vp = VirginProxy()  # reads VP_KEY
data = vp.create_job({
    "urls": ["https://shop.example/p/1", "https://shop.example/p/2"],
    "defaults": {"auto_extract": "product"},
    "delivery": {
        "destination": "dst_9Lk2Vb7Qx0Pm3Rn5Tz8W",
        "format": "ndjson",
        "path": "{date}/{job_id}.ndjson",
    },
})
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.createJob({
  urls: ["https://shop.example/p/1", "https://shop.example/p/2"],
  defaults: { auto_extract: "product" },
  delivery: {
    destination: "dst_9Lk2Vb7Qx0Pm3Rn5Tz8W",
    format: "ndjson",
    path: "{date}/{job_id}.ndjson",
  },
});
console.log(data);
```

**PHP**

```php
<?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",
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "urls" => ["https://shop.example/p/1", "https://shop.example/p/2"],
        "defaults" => ["auto_extract" => "product"],
        "delivery" => [
            "destination" => "dst_9Lk2Vb7Qx0Pm3Rn5Tz8W",
            "format" => "ndjson",
            "path" => "{date}/{job_id}.ndjson",
        ],
    ], 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;
```

**Go**

```go
package main

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

func main() {
	payload := []byte(`{
  "urls": [
    "https://shop.example/p/1",
    "https://shop.example/p/2"
  ],
  "defaults": {
    "auto_extract": "product"
  },
  "delivery": {
    "destination": "dst_9Lk2Vb7Qx0Pm3Rn5Tz8W",
    "format": "ndjson",
    "path": "{date}/{job_id}.ndjson"
  }
}`)
	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")

	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"])
}
```

POST`/v1/jobs`

| Field | Default | Meaning |
| --- | --- | --- |
| `delivery.destination` | required | The id of one of your destinations (`dst_…`). |
| `delivery.format` | `"ndjson"` | `ndjson`, `json`, `csv` – the same files as the [export](https://docs.virginproxy.com/jobs/#export). |
| `delivery.path` | `"{date}/{job_id}.ndjson"` | The file name inside the prefix. Placeholders: `{job_id}`, `{schedule_id}`, `{date}`, `{time}`, `{tag}`, `{kind}`. |

The same `delivery` works in a [crawl](https://docs.virginproxy.com/crawl/) and in the `job` or `crawl` of a [schedule](https://docs.virginproxy.com/automation/#schedules) – then every run writes its own file (use `{date}` or `{job_id}` in the path).

## Where it went

The job says it in `delivery`: `"status": "pending"` while it runs, then `"delivered"` with `key` and `bytes`, or `"failed"` with the reason. The file is written before the `job.done` [webhook](https://docs.virginproxy.com/webhooks/) goes out, so that webhook already names it. A failed delivery also shows as a notice in the dashboard; the results stay downloadable for 24 hours as usual.

NDJSON and CSV results larger than 90 MB are written as numbered parts (`name.part-0001.ndjson` …, split at line ends, listed in `delivery.keys`; a CSV has its header line in the first part only). A JSON file is one document and is not split: above 90 MB deliver `ndjson` instead. Results larger than 500 MB are not delivered – download those with the export.

> **Note:** Uploads come from our delivery network, not from a fixed address: if your bucket limits access by IP, use the key's permissions instead.
