createPolicy( )
Creates a policy.
Description
The createPolicy()
function returns a Promise that resolves to the newly-created policy.
You can create up to 3 policies per event. If you try to create more than 3, you'll get the "Maximum number of policies for the event has been reached" error.
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function createPolicy(policy: Policy): Promise<Policy>
createPolicy Parameters
NAME
TYPE
DESCRIPTION
Policy info.
Returns
Created policy.
Return Type:
NAME
TYPE
DESCRIPTION
Date and time when the policy was created.
Policy ID.
Date and time of the policy's latest update in.
Policy body, usually containing various terms and conditions.
Min: 1 character
Max: 50000 characters.
Note: You can format text using various HTML tags such as <p>
, <b>
, <ul>
, etc.
ID of the event to which the policy belongs.
Policy name that is visible in the dashboard and checkout form.
Min: 1 character
Max: 40 characters
Revision number, which increments by 1 each time the policy is updated. The existing revision must be used when updating a policy to prevent conflicting changes. You'll get an error if you try to use the previous revision.
Was this helpful?
1import { policies } from 'wix-events.v2';23//define policy object4const policy = {5 body: 'Tickets to this Event are issued on behalf of the Organiser and are subject to the following terms and conditions.',6 eventId: '9d720f99-1b5a-4141-9877-d32985391e18',7 name: 'Terms and Conditions Event 1'8};910//create policy11async function myCreatePolicyFunction(){12 try {13 const result = await policies.createPolicy(policy);14 return result;15 }16 catch (error) {17 console.error(error);18 // Handle the error19 }20 };2122/* Returns a promise that resolves to23 the created policy.24{25 "_id": "0907cf78-5177-4482-a627-b17ef06badec",26 "revision": "1",27 "_createdDate": "2023-03-07T12:48:25.917Z",28 "_updatedDate": "2023-03-07T12:48:25.917Z",29 "name": "Terms and Conditions Event 1",30 "body": "Tickets to this Event are issued on behalf of the Organiser and are subject to the following terms and conditions.",31 "eventId": "9d720f99-1b5a-4141-9877-d32985391e18"32}33*/34
1import { Permissions, webMethod } from 'wix-web-module';2import { policies } from 'wix-events.v2';3import { elevate } from 'wix-auth';45//define policy object6const policy = {7 body: 'Tickets to this Event are issued on behalf of the Organiser and are subject to the following terms and conditions.',8 eventId: '9d720f99-1b5a-4141-9877-d32985391e18',9 name: 'Terms and Conditions Event 1'10};1112//create policy13export const elevatedCreatePolicyFunction = webMethod(Permissions.Anyone, async () => {14 const elevatedCreatePolicy = elevate(policies.createPolicy);15 try {16 const result = await elevatedCreatePolicy(policy);17 return result;18 }19 catch (error) {20 console.error(error);21 // Handle the error22 }23 });2425/* Promise resolves to:26 * {27 * "_id": "0907cf78-5177-4482-a627-b17ef06badec",28 * "revision": "1",29 * "_createdDate": "2023-03-07T12:48:25.917Z",30 * "_updatedDate": "2023-03-07T12:48:25.917Z",31 * "name": "Terms and Conditions Event 1",32 * "body": "Tickets to this Event are issued on behalf of the Organiser and are subject to the following terms and conditions.",33 * "eventId": "9d720f99-1b5a-4141-9877-d32985391e18"34 * }35 */