-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
107 lines (90 loc) · 3.73 KB
/
example.py
File metadata and controls
107 lines (90 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""
Example usage of the KeyMint Python SDK
Before running this example:
1. Get your access token from: https://app.keymint.dev/dashboard/developer/access-tokens
2. Get your product ID from your KeyMint dashboard
3. Set environment variables:
export KEYMINT_ACCESS_TOKEN="your_token_here"
export KEYMINT_PRODUCT_ID="your_product_id_here"
"""
import os
import uuid
from keymint import KeyMintSDK, KeyMintApiError
def main():
# Get credentials from environment variables
access_token = os.environ.get('KEYMINT_ACCESS_TOKEN')
product_id = os.environ.get('KEYMINT_PRODUCT_ID')
if not access_token:
print("❌ Please set KEYMINT_ACCESS_TOKEN environment variable")
return
if not product_id:
print("❌ Please set KEYMINT_PRODUCT_ID environment variable")
return
print("🚀 KeyMint Python SDK Example")
print("-" * 40)
# Initialize the SDK
sdk = KeyMintSDK(access_token)
try:
# 1. Create a customer
print("1. Creating a customer...")
customer_response = sdk.create_customer({
'name': f'Example Customer {uuid.uuid4().hex[:8]}',
'email': f'example-{uuid.uuid4().hex[:8]}@example.com'
})
customer_id = customer_response['data']['id']
print(f" ✅ Customer created: {customer_id}")
# 2. Create a license key for the customer
print("2. Creating license key...")
license_response = sdk.create_key({
'productId': product_id,
'maxActivations': '3',
'customerId': customer_id
})
license_key = license_response['key']
print(f" ✅ License key created: {license_key}")
# 3. Get license key details
print("3. Getting license key details...")
key_details = sdk.get_key({
'productId': product_id,
'licenseKey': license_key
})
license_info = key_details['data']['license']
print(f" ✅ Max activations: {license_info['maxActivations']}")
print(f" ✅ Current activations: {license_info['activations']}")
# 4. Activate the license
print("4. Activating license...")
activate_response = sdk.activate_key({
'productId': product_id,
'licenseKey': license_key,
'hostId': f'example-device-{uuid.uuid4().hex[:8]}',
'deviceTag': 'Example Device'
})
print(f" ✅ License activated: {activate_response['message']}")
# 5. Check updated activation count
print("5. Checking updated activations...")
updated_details = sdk.get_key({
'productId': product_id,
'licenseKey': license_key
})
updated_activations = updated_details['data']['license']['activations']
print(f" ✅ Updated activations: {updated_activations}")
# 6. Get customer's license keys
print("6. Getting customer with license keys...")
customer_with_keys = sdk.get_customer_with_keys({
'customerId': customer_id
})
print(f" ✅ Retrieved customer with {len(customer_with_keys['data'].get('keys', []))} keys")
# 7. Clean up - delete the customer
print("7. Cleaning up...")
sdk.delete_customer({'customerId': customer_id})
print(" ✅ Customer deleted")
print("\n🎉 Example completed successfully!")
except KeyMintApiError as e:
print(f"\n❌ KeyMint API Error:")
print(f" Message: {e.message}")
print(f" Code: {e.code}")
print(f" Status: {e.status}")
except Exception as e:
print(f"\n❌ Unexpected error: {e}")
if __name__ == "__main__":
main()