---
url: https://docs.sunlicense.com/integrations/builtbybit.md
---
# BuiltByBit

BuiltByBit's **External license key** placeholder asks SunLicense for a key every time someone downloads
your resource and writes it into the file. Each buyer gets their own key, the same one on every
re-download, and you never send anything by hand.

::: tip A ready-made plugin
The [Paper plugin template](/guide/paper-plugin) and the [Hytale plugin template](/guide/hytale-plugin) already read this key, check it and handle every answer.
:::

## 1. Connect it in SunLicense

**Integrations → BuiltByBit → Connect.** Map your resource ID (the number at the end of the resource URL)
to a policy, or leave `*` for all your resources. SunLicense creates a secret for you.

## 2. Create the placeholder on BuiltByBit

1. **Creator dashboard → Placeholders → Create placeholder.**
2. **Placeholder:** a unique string, e.g. `%%__SUNLICENSE__%%`.
3. **Type:** *External license key*.
4. **URL:** the hook URL from the integration page.
5. **Secret:** the secret from the integration page.
6. Apply it to your resources, then **publish an update**: placeholders only apply to files uploaded after
   they exist.

## 3. Read the key in your plugin

```java
// BuiltByBit replaces this string with the buyer's SunLicense key when they download.
private static final String LICENSE_KEY = "%%__SUNLICENSE__%%";

@Override
public void onEnable() {
    SunLicense client = new SunLicense.Builder()
            .baseUrl("https://api.sunlicense.com")
            .token(API_KEY)                         // an API key from the API keys page
            .build();
    String serverId = getServer().getIp() + ":" + getServer().getPort();
    if (!client.validate(LICENSE_KEY, Map.of("host", serverId)).isValid()) {
        getLogger().severe("This copy is not licensed. Contact the author.");
        getServer().getPluginManager().disablePlugin(this);
    }
}
```

The policy's machine limit now applies per buyer: with *2 machines*, a buyer's key works on two servers.
If their jar leaks, open the license (the event log links to it, named *BuiltByBit user 4242*) and
**Revoke**: every copy of that jar stops validating within seconds.

## Optional: create the license at purchase time

The placeholder creates the license on the first download. To have it exist from the moment of purchase,
add a webhook: **Creator dashboard → Webhooks → Create webhook**, trigger *Purchase*, method POST,
content type JSON, URL = the same hook URL, and this custom body (the integration page fills in your secret):

```json
{"event":"purchase","secret":"<your secret>","user_id":"{user_id}","username":"{username}","resource_id":"{resource_id}"}
```

## Optional: buyers' names, pictures and portal sign-in

BuiltByBit usually tells SunLicense only a buyer's member ID. Paste your **Private** API token from [builtbybit.com/account/api](https://builtbybit.com/account/api) into the integration's **API token** field (BuiltByBit's API needs Ultimate). SunLicense then:

* shows each buyer's BuiltByBit name and picture on **Customers**, fetched in the background and refreshed weekly (never during a purchase or a license check);
* links the Discord account their BuiltByBit profile names, so keys can go by Discord DM and they can *Sign in with Discord* to your [customer portal](/guide/customer-portal#builtbybit-buyers);
* offers *Sign in with BuiltByBit* in the portal: the buyer gets their sign-in link as a BuiltByBit message from your account.

Without a token, buyers show as "BuiltByBit member 48213" with a link to their profile.

## What SunLicense receives

| Field | Used for |
|---|---|
| `secret` | Must equal the integration's secret, or the request is refused (401) |
| `user_id`, `resource_id` | One license per buyer per resource; `resource_id` picks the policy |
| `version_id`, `version_number`, `steam_id`, `builtbybit` | Ignored |

SunLicense answers with the key as plain text. On any problem (wrong secret, unmapped resource, plan
limit) it answers with an error status, and BuiltByBit fills the placeholder with its "contact the
creator" message instead of an error text.

::: warning Before you announce it
BuiltByBit doesn't publish the exact reply format it expects from an external license server. Do one
real test download and check that your jar contains a key like `K7QX-M2PD-9HWT-R4CN`.
:::

::: tip Refunds
The placeholder carries no refund information. Revoke refunded buyers from the license page.
:::
