Skip to content
VPNDetection

API

Download VPNDetection's databases on your own schedule through the Database API, skip builds that haven't changed, and check each file's SHA-256.

View as Markdown

The Database API downloads any database your organization holds a license for, the Open ones included, with an API key carrying the db.download scope. It suits a job that runs on your own schedule, and it's what the CLI and the client libraries call.

A download answers with a 302 redirect to a time-limited link, so the bytes come straight from object storage. The link only has to be valid when the download starts, so a long download isn't cut off when it expires. To have new builds come to you instead of fetching them, use Database Delivery.

Before you begin

  • An API key with the db.download scope, which the console shows as Download databases among the key's Permissions. Your organization's Default key has it.
  • A license for the database you want. Every organization holds the Open databases from the start.
  • curl, and sha256sum to check the file, or shasum -a 256 on macOS.

To keep the key out of your scripts, store it in an environment variable:

bash
export VPNDETECTION_API_KEY="YOUR_API_KEY"

1. Find the database's ID

A download names a database by its ID, which carries its version, such as vpn_ip_v1. Each dataset's page in the Database Reference shows its ID, and List returns every database with your organization's standing for each, licensed, expired or unlicensed:

bash
curl -H "Authorization: Bearer $VPNDETECTION_API_KEY" https://api.vpndetection.io/api/v1/database/list

Pass a version's id from that answer, never the family's base: vpn_ip_v1, not vpn_ip.

2. Check whether a new build is out

To avoid downloading a file you already have, ask for the database's Metadata first. It needs no license, and its updated field is the current build's date and entries its row count:

bash
curl -H "Authorization: Bearer $VPNDETECTION_API_KEY" "https://api.vpndetection.io/api/v1/database/metadata?id=vpn_ip_v1"

A daily job compares updated with the date of the copy it holds, and skips a database that hasn't changed.

3. Download the file

Ask for the database and its format, and let curl follow the redirect to the file with -L:

bash
curl -L -o vpn_ip_v1.mmdb "https://api.vpndetection.io/api/v1/database/download?id=vpn_ip_v1&format=mmdb&apikey=$VPNDETECTION_API_KEY"

format is csvgz or mmdb, whichever the database is built in, as its page lists. Formats explains each one.

4. Check the file

Checksums gives each file's SHA-256, among other digests, so you can check a copy once it lands:

bash
curl -H "Authorization: Bearer $VPNDETECTION_API_KEY" "https://api.vpndetection.io/api/v1/database/checksum?id=vpn_ip_v1&format=mmdb"

Its checksums.sha256 is the digest of the current build's file. Compute your copy's and compare the two:

bash
sha256sum vpn_ip_v1.mmdb

The values match for an intact file. A mismatch means the file is truncated, corrupted or from a different build, so download it again.

Verify that a download worked

Download history lists every download your organization made, refusals included, each with its outcome and status. The console shows the same list under Database > Download history.

When a download fails

A refused download answers with a status and a result code, rc, which says what to change:

StatusrcWhat to do
401UNAUTHORIZEDSend a valid key that carries the db.download scope.
403NOT_LICENSEDYour organization holds no license for this database, so choose one it holds.
403LICENSE_EXPIREDYour organization's license for this database has ended, so renew it.
403KEY_OVER_HTTPSend the request to https://, never plain http://.
404UNKNOWN_DATASETPass a version's ID, such as vpn_ip_v1, rather than the family's base.
400INVALID_FORMATAsk for a format the database is built in.
400INVALID_BUILDPass a build's name in build, or leave build out.
410BUILD_GONEThe build named in build is no longer kept, so download without build for the live one.
503NOT_AVAILABLEToday's copy hasn't been published yet, so try again later.

Builds are kept for 7 days, which is why a link that names an older build answers 410. Which credential each endpoint takes is on Authentication.

Next steps

You can now download a database, skip builds you already have and check each file. To have new builds come to you instead, announce them to a webhook, whose payload carries these same download links, or have them written to your own storage: AWS S3, Google Cloud Storage, Azure Blob Storage or SFTP.