title | description |
---|---|
Downloadable Software |
License Keys documentation guide |
A License Key is a unique identifier generated by Whop for each user who has made a purchase. It acts like a special access code that users can input to gain access to your application.
License Keys are useful when you want to sell & restrict access to desktop applications. For example, if you're selling a game, you can use license keys to restrict access to users who have purchased the game.
If you haven't already created your company or made a product to sell, you'll want to start there.
Once you've done that, head to the dashboard to add the license key experience to your product.
A download link is required to add a **Software** experience. This is the link that will appear in the user's dashboard to download the software.For the endpoints below, you'll need to use your API key. You can find your API key in the dashboard under the Developer
tab.
- Head to your Developers settings page
- Click New API Key
- Set a memorable name for your key.
- Copy the API key
Metadata is a way to store information about a license key. The most common use case for this is to store information about the user's device, HWID. Hardware ID is a unique identifier for a device, and can be used to prevent users from sharing their license keys with others.
The user can reset their metadata anytime by going to their dashboard and clicking the `Reset Key` button. ```js JavaScript const machineId = require('node-machine-id');function generate_hwid() {
return machineId.machineIdSync();
}
```
import hashlib
import platform
def generate_hwid():
return hashlib.sha256(platform.node().encode()).hexdigest().strip()
The metadata field in the body is required. If you do not wish to set any metadata, you can pass an empty object.
{ "metadata": {} }
async function validateLicense(licenseKey, HWID) {
const url = `https://api.whop.com/api/v2/memberships/${licenseKey}/validate_license`;
const payload = {
metadata: {
HWID: HWID,
},
};
const headers = {
Accept: "application/json",
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
};
const response = await fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(payload),
});
return response;
}
```
```python Python
import requests
def validate_license(license_key, HWID):
url = f"https://api.whop.com/api/v2/memberships/{license_key}/validate_license"
payload = {"metadata": {"HWID": HWID}}
headers = {
"accept": "application/json",
"Authorization": f"Bearer {API_KEY}",
"content-type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
return response
```
Here are the most common responses from this endpoint.
Status Code | Description |
---|---|
201 | The license key is valid and the user can use the product |
400 | The metadata did not match; the user needs to reset their key |
404 | The license key was not found |