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.
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.downloadscope, which the console shows as Download databases among the key's Permissions. Your organization'sDefaultkey has it. - A license for the database you want. Every organization holds the Open databases from the start.
curl, andsha256sumto check the file, orshasum -a 256on macOS.
To keep the key out of your scripts, store it in an environment variable:
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:
curl -H "Authorization: Bearer $VPNDETECTION_API_KEY" https://api.vpndetection.io/api/v1/database/listPass 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:
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:
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:
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:
sha256sum vpn_ip_v1.mmdbThe 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:
| Status | rc | What to do |
|---|---|---|
401 | UNAUTHORIZED | Send a valid key that carries the db.download scope. |
403 | NOT_LICENSED | Your organization holds no license for this database, so choose one it holds. |
403 | LICENSE_EXPIRED | Your organization's license for this database has ended, so renew it. |
403 | KEY_OVER_HTTP | Send the request to https://, never plain http://. |
404 | UNKNOWN_DATASET | Pass a version's ID, such as vpn_ip_v1, rather than the family's base. |
400 | INVALID_FORMAT | Ask for a format the database is built in. |
400 | INVALID_BUILD | Pass a build's name in build, or leave build out. |
410 | BUILD_GONE | The build named in build is no longer kept, so download without build for the live one. |
503 | NOT_AVAILABLE | Today'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.