# Quickstart

> From no account to a working check in a few minutes.

## 1. Create an API key

1. Sign up at [https://heimdal.codebrewerz.com](https://heimdal.codebrewerz.com) and start the 7-day trial.
2. In the dashboard, open **API keys** and create a key.
3. Copy it. The full key is shown once and starts with `hd_`.

Put the key in an environment variable on your server. The examples below read it from `HEIMDAL_API_KEY`.

```sh
export HEIMDAL_API_KEY="hd_your_key"
```

## 2. Make a request

Send an IP address, an email address, or both. This example sends an address that has served as a Tor exit node and a mailbox at a well-known disposable provider.

**curl**

```sh
curl -X POST "https://heimdal.codebrewerz.com/api/v1/check" \
  -H "Authorization: Bearer $HEIMDAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"ip":"185.220.101.1","email":"test@mailinator.com"}'
```

**Node (fetch)**

```js
const response = await fetch("https://heimdal.codebrewerz.com/api/v1/check", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.HEIMDAL_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ ip: "185.220.101.1", email: "test@mailinator.com" }),
  signal: AbortSignal.timeout(2000),
});

console.log(await response.json());
```

**Node (axios)**

```js
import axios from "axios";

const { data } = await axios.post(
  "https://heimdal.codebrewerz.com/api/v1/check",
  { ip: "185.220.101.1", email: "test@mailinator.com" },
  {
    headers: { Authorization: `Bearer ${process.env.HEIMDAL_API_KEY}` },
    timeout: 2000,
  },
);

console.log(data);
```

**Python**

```python
import os

import requests

response = requests.post(
    "https://heimdal.codebrewerz.com/api/v1/check",
    json={"ip": "185.220.101.1", "email": "test@mailinator.com"},
    headers={"Authorization": f"Bearer {os.environ['HEIMDAL_API_KEY']}"},
    timeout=2,
)

print(response.json())
```

**Java**

```java
// Java 11+, no dependencies.
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 Check {
    public static void main(String[] args) throws Exception {
        String key = System.getenv("HEIMDAL_API_KEY");
        if (key == null || key.isBlank()) {
            throw new IllegalStateException("Set HEIMDAL_API_KEY");
        }
        HttpClient client = HttpClient.newBuilder()
            .connectTimeout(Duration.ofSeconds(2))
            .build();
        HttpRequest request = HttpRequest.newBuilder(URI.create("https://heimdal.codebrewerz.com/api/v1/check"))
            .timeout(Duration.ofSeconds(2))
            .header("Authorization", "Bearer " + key)
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString("{\"ip\":\"185.220.101.1\",\"email\":\"test@mailinator.com\"}"))
            .build();
        HttpResponse<String> response =
            client.send(request, HttpResponse.BodyHandlers.ofString());
        // 200: the check. Anything else: {"error":{"code","message"}}.
        System.out.println(response.statusCode() + " " + response.body());
    }
}
```

**Rust**

```rust
// Cargo.toml
// [dependencies]
// reqwest = { version = "0.13", features = ["json", "query"] }
// serde_json = "1"
// tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let key = std::env::var("HEIMDAL_API_KEY")?;
    let client = reqwest::Client::builder()
        .timeout(Duration::from_secs(2))
        .build()?;
    let response = client
        .post("https://heimdal.codebrewerz.com/api/v1/check")
        .bearer_auth(&key)
        .json(&serde_json::json!({"ip":"185.220.101.1","email":"test@mailinator.com"}))
        .send()
        .await?;
    // 200: the check. Anything else: {"error":{"code","message"}}.
    let status = response.status();
    let answer: serde_json::Value = response.json().await?;
    println!("{status} {answer}");
    Ok(())
}
```

**Go**

```go
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"strings"
	"time"
)

func main() {
	client := &http.Client{Timeout: 2 * time.Second}
	req, err := http.NewRequest("POST", "https://heimdal.codebrewerz.com/api/v1/check", strings.NewReader(`{"ip":"185.220.101.1","email":"test@mailinator.com"}`))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("HEIMDAL_API_KEY"))
	req.Header.Set("Content-Type", "application/json")

	res, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)
	fmt.Println(string(body))
}
```

**PHP**

```php
<?php
// composer require guzzlehttp/guzzle
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client(['timeout' => 2]);
$response = $client->post("https://heimdal.codebrewerz.com/api/v1/check", [
    'headers' => ['Authorization' => 'Bearer ' . getenv('HEIMDAL_API_KEY')],
    'json' => ['ip' => "185.220.101.1", 'email' => "test@mailinator.com"],
]);

echo $response->getBody();
```

## 3. Read the answer

```json
{
  "block": true,
  "reasons": ["disposable_email", "tor", "vpn", "bad_isp"],
  "email": {
    "address": "test@mailinator.com",
    "domain": "mailinator.com",
    "disposable": true
  },
  "ip": {
    "address": "185.220.101.1",
    "tor": true,
    "vpn": true,
    "proxy": false,
    "bad_isp": true,
    "asn": 60729,
    "isp": "TORSERVERS-NET Stiftung Erneuerbare Freiheit"
  },
  "custom": { "matched": [] }
}
```

- `block` is the short answer: `true` when any signal fired.
- `reasons` names the signals that fired.
- `email` and `ip` hold the detail for each value you sent. A value you did not send comes back as `null`.

:::note
The lists change every hour, so the `ip` part of your answer can differ from this one. The network name comes from the lists too.
:::

## 4. Decide

The simplest integration refuses the signup when `block` is `true`:

```js
const result = await response.json();

if (result.block) {
  // Refuse the signup, or ask for more proof.
}
```

`block` is strict: it is also `true` for an ordinary person on a VPN. Most products want something softer, such as refusing disposable email, Tor and open proxies while only logging VPN and hosting networks. Read [Best practices](https://heimdal.codebrewerz.com/docs/guides/best-practices/) before you ship.

## Next steps

- [Check endpoint](https://heimdal.codebrewerz.com/docs/reference/check/): every parameter and response field.
- [Signals explained](https://heimdal.codebrewerz.com/docs/reference/signals/): what each signal means.
- [Node.js guide](https://heimdal.codebrewerz.com/docs/guides/node/): a complete helper with a timeout that fails open.
