Each example creates an order, waits for it to finish, and saves the PDF. Pick your language on any code block and the whole page follows.
| Language | Needs |
|---|---|
| cURL | Bash, curl and jq. |
| PHP | PHP 8.1+ and Guzzle (composer require guzzlehttp/guzzle). |
| Java | Java 17+ (the built-in java.net.http client) and Jackson for JSON. |
| Python | Python 3.8+ and requests (pip install requests). |
#!/usr/bin/env bash
set -euo pipefail
BASE="https://www.vinservicehistory.com/api/v1"
VIN="WBA3A5C50CF256651"
api() { curl -sSf -H "Authorization: Bearer $VINHISTORY_KEY" -H "Accept: application/json" "$@"; }
NUMBER=$(api "$BASE/orders" -H "Content-Type: application/json" -d "{
\"brand\": \"bmw\",
\"vin\": \"$VIN\",
\"customer_name\": \"Ali Hassan\",
\"customer_email\": \"[email protected]\"
}" | jq -r '.data.number')
for _ in $(seq 60); do
sleep 30
ORDER=$(api "$BASE/orders/$NUMBER")
STATUS=$(jq -r '.data.status' <<< "$ORDER")
if [ "$STATUS" = "completed" ]; then
# The signed link needs no token.
curl -sSf -o "$VIN.pdf" "$(jq -r '.data.report_url' <<< "$ORDER")"
break
fi
if [ "$STATUS" = "cancelled" ]; then
echo "No records found for this vehicle."
break
fi
done
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$api = new Client([
'base_uri' => 'https://www.vinservicehistory.com/api/v1/',
'headers' => [
'Authorization' => 'Bearer '.getenv('VINHISTORY_KEY'),
'Accept' => 'application/json',
],
]);
$order = json_decode($api->post('orders', ['json' => [
'brand' => 'bmw',
'vin' => 'WBA3A5C50CF256651',
'customer_name' => 'Ali Hassan',
'customer_email' => '[email protected]',
]])->getBody(), true)['data'];
for ($i = 0; $i < 60 && $order['status'] === 'processing'; $i++) {
sleep(30);
$order = json_decode($api->get("orders/{$order['number']}")->getBody(), true)['data'];
}
if ($order['status'] === 'completed') {
// The signed link needs no token.
(new Client)->get($order['report_url'], ['sink' => "{$order['vin']}.pdf"]);
} elseif ($order['status'] === 'cancelled') {
echo "No records found for this vehicle.\n";
}
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Path;
import java.util.Map;
public class OrderReport {
static final String BASE = "https://www.vinservicehistory.com/api/v1";
static final HttpClient http = HttpClient.newHttpClient();
static final ObjectMapper json = new ObjectMapper();
public static void main(String[] args) throws Exception {
String body = json.writeValueAsString(Map.of(
"brand", "bmw",
"vin", "WBA3A5C50CF256651",
"customer_name", "Ali Hassan",
"customer_email", "[email protected]"));
JsonNode order = call(HttpRequest.newBuilder(URI.create(BASE + "/orders"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body)));
for (int i = 0; i < 60 && order.get("status").asText().equals("processing"); i++) {
Thread.sleep(30_000);
order = call(HttpRequest.newBuilder(URI.create(BASE + "/orders/" + order.get("number").asText())));
}
switch (order.get("status").asText()) {
// The signed link needs no token.
case "completed" -> http.send(
HttpRequest.newBuilder(URI.create(order.get("report_url").asText())).build(),
HttpResponse.BodyHandlers.ofFile(Path.of(order.get("vin").asText() + ".pdf")));
case "cancelled" -> System.out.println("No records found for this vehicle.");
default -> System.out.println("Still processing; check again later.");
}
}
static JsonNode call(HttpRequest.Builder request) throws Exception {
HttpResponse<String> response = http.send(request
.header("Authorization", "Bearer " + System.getenv("VINHISTORY_KEY"))
.header("Accept", "application/json")
.build(), HttpResponse.BodyHandlers.ofString());
if (response.statusCode() >= 400) {
throw new IllegalStateException(response.statusCode() + " " + response.body());
}
return json.readTree(response.body()).get("data");
}
}
import os
import time
import requests
base = "https://www.vinservicehistory.com/api/v1"
api = requests.Session()
api.headers.update({
"Authorization": f"Bearer {os.environ['VINHISTORY_KEY']}",
"Accept": "application/json",
})
r = api.post(f"{base}/orders", json={
"brand": "bmw",
"vin": "WBA3A5C50CF256651",
"customer_name": "Ali Hassan",
"customer_email": "[email protected]",
})
r.raise_for_status()
order = r.json()["data"]
for _ in range(60):
if order["status"] != "processing":
break
time.sleep(30)
r = api.get(f"{base}/orders/{order['number']}")
r.raise_for_status()
order = r.json()["data"]
if order["status"] == "completed":
# The signed link needs no token.
with open(f"{order['vin']}.pdf", "wb") as f:
f.write(requests.get(order["report_url"]).content)
elif order["status"] == "cancelled":
print("No records found for this vehicle.")