Pricing
To retrieve prices from our API in the same format as the CSV export option in our portal does, you can use the below example and retrieeve the npricing information from our API.
1 import requests
2 from typing import TypedDict, List, Literal, TypeAlias, Dict, Optional
3
4 CUSTOMER = "CUSTOMER"
5 API_KEY = "YOUR_API_KEY"
6
7 ProductBillableAction: TypeAlias = Literal[
8 "CREATE",
9 "EXTRA_DOMAIN",
10 "EXTRA_WILDCARD",
11 "LOCAL_CONTACT",
12 "PRIVACY_PROTECT",
13 "REGISTRANT_CHANGE",
14 "REGISTRY_LOCK",
15 "RENEW",
16 "REQUEST",
17 "RESTORE",
18 "TRANSFER",
19 "TRANSFER_RESTORE",
20 "UPDATE"
21 ]
22
23 class PriceResponse(TypedDict):
24 """
25 Basic price entry.
26
27 :cvar product: Name of the product e.g., "domain_nl".
28 :cvar action: Type of action e.g., "RENEW" or "UPDATE".
29 :cvar currency: Currency of the displayed product price e.g., "USD".
30 :cvar price: Price of the product.
31 """
32 product: str
33 action: ProductBillableAction
34 currency: str
35 price: int
36
37 class PriceChangeResponse(PriceResponse):
38 """
39 Price entry for price changes.
40
41 :cvar product: Name of the product e.g., "domain_nl".
42 :cvar action: Type of action e.g., "RENEW" or "UPDATE".
43 :cvar currency: Currency of the displayed product price e.g., "USD".
44 :cvar price: Price of the product.
45 :cvar fromDate: Timestamp from when the price change will become active.
46 """
47 fromDate: str
48
49 class PromoResponse(PriceChangeResponse):
50 """
51 Price entry for promotions.
52
53 :cvar product: Name of the product e.g., "domain_nl".
54 :cvar action: Type of action e.g., "RENEW" or "UPDATE".
55 :cvar currency: Currency of the displayed product price e.g., "USD".
56 :cvar price: Price of the product.
57 :cvar fromDate: Timestamp from when the promotion will become active.
58 :cvar endDate: Timestamp when the promotion ends.
59 :cvar active: Whether the promotion is active.
60 """
61 endDate: str
62 active: bool
63
64 class PriceListResponse(TypedDict):
65 """
66 A dictionary as returned by the request to the RTR "/pricelist" endpoint.
67 :cvar prices: A list of basic price entries.
68 :cvar priceChanges: A list of price changes.
69 :cvar promos: A list of promotions.
70 """
71 prices: List[PriceResponse]
72 priceChanges: List[PriceChangeResponse]
73 promos: List[PromoResponse]
74
75 response: PriceListResponse = requests.get(
76 f"https://api.yoursrs.com/v2/customers/{CUSTOMER}/pricelist",
77 headers={"Authorization": f"ApiKey {API_KEY}"}
78 ).json()
79
80 def get_grouped_regular_prices():
81 """
82 Groups all regular prices by product.
83 :return: A dictionary where each key represents a product with a dictionary containing prices and its currency.
84 """
85 groups = {}
86
87 for product in response["prices"]:
88 product_name = product["product"]
89 if product_name not in groups:
90 groups[product_name] = dict(prices={}, currency=product["currency"])
91
92 groups[product_name]["prices"][product["action"]] = product["price"]
93
94 return groups
95
96 def get_domain_prices() -> Dict[str, dict]:
97 """
98 Get all domain prices.
99 :return: A dictionary where each key represents a product with a dictionary containing prices and its currency.
100 """
101 prices = get_grouped_regular_prices()
102 return { k:v for k,v in prices.items() if k.startswith('domain_') }
103
104 domain_prices = get_domain_prices()