VAS products
Lists the value-added service (VAS) products configured for your organisation — the products you're entitled to sell, the providers behind each, and the format hints to validate user input against before sending a purchase.
List enabled products
http
GET /v1/vas-productsbash
curl https://api.scratchpower.com/v1/vas-products \
-H "Authorization: Bearer $TOKEN"js
const res = await fetch("https://api.scratchpower.com/v1/vas-products", {
headers: { Authorization: `Bearer ${token}` },
});
const products = await res.json();python
resp = requests.get(
"https://api.scratchpower.com/v1/vas-products",
headers={"Authorization": f"Bearer {token}"},
)
products = resp.json()Response
json
[
{
"product_type": "ELECTRICITY",
"display_name": "Electricity",
"subscriber_id_label": "Meter Number",
"subscriber_id_min_length": 11,
"subscriber_id_max_length": 13,
"subscriber_id_pattern": "^[0-9]{11,13}$",
"subscriber_id_hint": null,
"providers": [
{ "code": "BPC", "name": "Botswana Power Corporation" }
]
}
]Fields
| Field | Type | Notes |
|---|---|---|
product_type | string | One of ELECTRICITY, AIRTIME, WATER |
display_name | string | Localised label safe to show to users |
subscriber_id_label | string | null | What to label the input ("Meter Number", "Phone Number", ...) |
subscriber_id_min_length | integer | null | Minimum number of characters |
subscriber_id_max_length | integer | null | Maximum number of characters |
subscriber_id_pattern | string | null | JS-compatible regex the value must match |
subscriber_id_hint | string | null | Free-form admin-curated description (overrides auto-derived hint) |
providers | array | Providers offering this product to your org |
Subscriber ID validation
Apply length AND pattern in tandem on the client. For displaying the
hint to users, prefer subscriber_id_hint when it's set, otherwise
synthesise from min/max:
js
function validate(product, value) {
const min = product.subscriber_id_min_length;
const max = product.subscriber_id_max_length;
const pat = product.subscriber_id_pattern;
if (min != null && value.length < min) return false;
if (max != null && value.length > max) return false;
if (pat && !new RegExp(pat).test(value)) return false;
return true;
}Different providers within the same product type may have different
subscriber ID formats. The format on the product is the loosest envelope
— providers may further validate during the call to /purchases/validate.