Creates a tier.
The name for a tier and the amount of required points to qualify for a tier can only exist for a single tier.
Attempts to create a tier with a tierDefinition.name
or requiredPoints
that already exists will return an error.
To create up to 20 tiers at once, use bulkCreateTiers()
.
Note: You must have a Business VIP Premium plan or a Scale Premium plan to add tiers.
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function createTier(tier: Tier): Promise<Tier>;
Tier to create.
import { tiers } from "wix-loyalty.v2";
import { webMethod, Permissions } from "wix-web-module";
import { elevate } from "wix-auth";
/* Sample tier value:
* {
* "tier": {
* "required_points": 1000,
* "tierDefinition": {
* "name": "Jadeite Tier",
* "description": "Jadeite Tier Benefits",
* "icon": {
* "url": "shapes/cca51dde12d348379113f2201cbe4e6c.svg"
* }
* }
* }
* }
*/
const elevatedCreateTier = elevate(tiers.createTier);
export const createTier = webMethod(Permissions.Anyone, async (tier) => {
try {
const result = await elevatedCreateTier(tier);
return result;
} catch (error) {
console.error(error);
// Handle the error
}
});
/* Promise resolves to:
* {
* "tier": {
* "_createdDate": "2024-06-11T12:38:35.490Z",
* "_id": "8edeea05-2c90-43fa-bd15-b2352620fd51",
* "_updatedDate": "2024-06-11T12:38:35.490Z",
* "requiredPoints": 1000,
* "revision": "1",
* "tierDefinition": {
* "description": "Jadeite Tier Benefits",
* "icon": {
* "id": "",
* "url": "shapes/cca51dde12d348379113f2201cbe4e6c.svg",
* "height": 0,
* "width": 0,
* "altText": null,
* "urlExpirationDate": null,
* "filename": null,
* "sizeInBytes": null
* },
* "name": "Jadeite Tier"
* }
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.