Gumroad provides key features for API management like license key validation, usage tracking and access management through their License API.
The /licenses/verify
endpoint is particularly useful for tracking API usage. Each request to your
API can be
logged and compared against a user's allocation.
Here's a basic implementation of usage tracking through Gumroad License API:
url = "https://api.gumroad.com/v2/licenses/verify"
data = {
"product_id": "YOUR_PRODUCT_ID",
"license_key": "CUSTOMERS_LICENSE_KEY",
"increment_uses_count": "true",
}
response = requests.post(url, data=data)
uses = response.json()["uses"]
assert uses < 100, "Usage limit exceeded"
The fields are:
product_id
: Gumroad product ID of the product you're selling.license_key
: The license key of the customer. Gumroad emails the license key to the customer
after purchase. They have to send this key to your API on every request.increment_uses_count
: Whether to increment the usage count. You can turn this off for
non-usage related requests.