getSubscription()
Returns the subscription the site belongs to: the plan, the monthly price, the limits, this month's usage of storage, transfer, users and AI, and the users with access to the subscription's workspaces. Use it to show a customer's administrator what the solution costs and who uses it.
The function only ever returns the site's own subscription (the one on the site's workspace) and takes no arguments. It returns null when the workspace has no subscription.
Available in API scripts only, like promptAI: the answer contains the users' e-mail addresses, and a page is cached and shown to every visitor.
Parameters
This function takes no parameters.
Returns
null when the site's workspace has no subscription. Otherwise an object:
plan: "Start", "Business", "Advanced", "Enterprise", or "Custom" when the limits are not a standard plan.name: the subscription's name.monthlyPriceandcurrency: the monthly price excluding VAT, for example 365 and "NOK".monthlyPriceis null when the price is by agreement.limits:storageGb,transferGb(per month, including ordered add-ons),users(user licenses) andworkspaces. null means no fixed limit.period:month("yyyy-MM"),daysin the month, andupdated, when the usage was last summed up (UTC, null before the first time).usage:storageGbstored now,transferGbthis month,userswith access (the user licenses in use, to compare withlimits.users; everyone inuserscounts, also those who only have access to the website), andaiwithcost,currencyandcalls.storageGbPerDay,transferGbPerDayandai.costPerDayhave one entry per day of the month (UTC, index 0 is the 1st); a day without a storage measurement is null.users: an array of{ email, access, lastLogin }for the owners and everyone with an accepted share in the subscription's workspaces, also those who only have access to the website.accessis the strongest the user has: "owner", "admin", "edit", "read" or "web".lastLoginis an ISO date, or null if the user has never signed in. The most recent sign-in comes first.
GB are decimal (1 GB = 1,000,000,000 bytes). The AI cost is in the currency Docly records it in (ai.currency, "USD"); convert it yourself if you show it in another currency.
Throws error 1 if the subscription cannot be read right now, or no answer arrives within the script's execution timeout.
Example
let sub = docly.getSubscription();
if (sub == null) return { subscription: false };
return {
plan: sub.plan,
price: sub.monthlyPrice,
currency: sub.currency,
storageUsedGb: sub.usage.storageGb,
storageLimitGb: sub.limits.storageGb,
userLicenses: sub.limits.users,
usersWithAccess: sub.usage.users,
aiCost: sub.usage.ai.cost,
aiCurrency: sub.usage.ai.currency,
users: sub.users
};