Search.../

queryPublicPlans( )

Creates a query to retrieve a list of public pricing plans.

Description

The queryPublicPlans() function builds a query to retrieve a list of up to 1,000 public plans and returns a PublicPlansQueryBuilder object.

The returned object contains the query definition which is typically used to run the query using the find() function.

You can refine the query by chaining PublicPlansQueryBuilder functions onto the query. PublicPlansQueryBuilder functions enable you to sort, filter, and control the results that queryPublicPlans() returns.

queryPublicPlans() runs with the following PublicPlansQueryBuilder defaults that you can override:

The functions that are chained to queryPublicPlans() are applied in the order they are called. For example, if you sort on the _createdDate property in ascending order and then on the _id property in ascending order, the results are sorted first by the created date of the items and then, if there are multiple results with the same date, the items are sorted by _id in ascending order, per created date value.

The following PublicPlansQueryBuilder functions are supported for queryPublicPlans().

PropertyFiltersExamples
_ideq(), ne(), hasSome()hasSome("_id", ["46ce4cd4-46ff-13a1-43ac-02fd4f0f3209", "94ce4cd4-46cc-20c3-4c7a-03fd4f0f3306"])
primaryeq(), ne(), ascending(), descending()eq("primary",true)
slugeq(), ne(), startsWith(), endsWith(), contains(), ascending(), descending()eq("gold")
_createdDateeq(), ne(), gt(), ge(), lt(), le(), between(), ascending(), descending()lt("_createdDate", "2020-04-27T10:00:00.000Z")
_updatedDateeq(), ne(), gt(), ge(), lt(), le(), between(), ascending(), descending()ge("_updatedDate", "2020-04-27T10:00:00.000Z")

Notes:

  • When using the queryPublicPlans() function immediately following a change to your plans, the data retrieved may not contain your most recent changes. See Wix-data and Eventual Consistency for more information. To solve this problem, you can use the setTimeout() function to delay querying following any changes to your plan data. The find() function executes the query based on this query object, and returns the actual result, PublicPlansQueryResult.
  • You do not need "Manage Pricing Plans" permissions to query public plans.

Syntax

function queryPublicPlans(): Promise<PublicPlansQueryBuilder>

queryPublicPlans Parameters

This function does not take any parameters.

Returns

Fulfilled - The query definition used to run the query using the find() function.

Return Type:

Was this helpful?

Build and execute a query to find all public plans

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import wixPricingPlansBackend from 'wix-pricing-plans-backend';
3
4export const myQueryPublicPlansFunction = webMethod(Permissions.Anyone, () => {
5 return wixPricingPlansBackend.queryPublicPlans()
6 .find()
7 .then((result) => {
8 console.log(result);
9 })
10 .catch((error) => {
11 console.error(error);
12 });
13});
14
15// Query results
16/*
17 * {
18 * "items": [
19 * {
20 * "_id": "3fb6a3c8-988b-7896-04bd-6c69ae0b18eb",
21 * "name": "Gold",
22 * "description": "For expert gamers",
23 * "perks": [
24 * "Great value for your money",
25 * "Multi-user"
26 * ],
27 * "pricing": {
28 * "singlePaymentUnlimited": true,
29 * "price": {
30 * "value": "100",
31 * "currency": "USD"
32 * }
33 * },
34 * "primary": false,
35 * "_createdDate": "2020-12-21T15:13:06.202Z",
36 * "_updatedDate": "2020-12-30T17:10:01.202Z",
37 * "slug": "gold",
38 * "maxPurchasesPerBuyer": 1,
39 * "allowFutureStartDate": false,
40 * "buyerCanCancel": true
41 * },
42 * {
43 * "_id": "9e76b9dc-a3a6-3e25-ada5-a1ace10ccbeb",
44 * "name": "Gold Plus",
45 * "description": "Updated description for the original Gold plan",
46 * "perks": [
47 * "Multiplayer",
48 * "Multiple devices",
49 * "No ads",
50 * "Unlimited access"
51 * ],
52 * "pricing": {
53 * "subscription": {
54 * "cycleDuration": {
55 * "count": 1,
56 * "unit": "MONTH"
57 * },
58 * "cycleCount": 3
59 * },
60 * "price": {
61 * "value": "23",
62 * "currency": "USD"
63 * },
64 * "freeTrialDays": 7
65 * },
66 * "primary": false,
67 * "_createdDate": "2020-12-21T15:14:08.018Z",
68 * "_updatedDate": "2020-12-30T15:13:07.018Z",
69 * "slug": "gold-plus",
70 * "allowFutureStartDate": false,
71 * "buyerCanCancel": true,
72 * "termsAndConditions": ""
73 * },
74 * {
75 * "_id": "22f234bf-a3a6-7c32-abc1-88101ffcb2ef",
76 * "name": "Silver",
77 * "description": "For advanced gamers",
78 * "perks": [
79 * "Great avatar selection and background tunes",
80 * "All perks of Bronze membership"
81 * ],
82 * "pricing": {
83 * "singlePaymentForDuration": {
84 * "count": 3,
85 * "unit": "MONTH"
86 * },
87 * "price": {
88 * "value": "24",
89 * "currency": "USD"
90 * }
91 * },
92 * "primary": false,
93 * "_createdDate": "2020-12-21T15:13:10.327Z",
94 * "_updatedDate": "2020-12-30T19:02:13.327Z",
95 * "slug": "silver",
96 * "allowFutureStartDate": false,
97 * "buyerCanCancel": true,
98 * "termsAndConditions": ""
99 * }
100 * ]
101 * }
102 */
Build and execute a query to find public plans created before a certain date

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import wixPricingPlansBackend from 'wix-pricing-plans-backend';
3
4export const myQueryPublicPlansFunction = webMethod(Permissions.Anyone, () => {
5 return wixPricingPlansBackend.queryPublicPlans()
6 .lt("_createdDate", "2021-01-15T10:00:00.000Z")
7 .find()
8 .then((result) => {
9 console.log(result);
10 })
11 .catch((error) => {
12 console.error(error);
13 });
14});
15
16// Query results
17/*
18 * {
19 * "items": [
20 * {
21 * "_id": "3fb6a3c8-988b-7896-04bd-6c69ae0b18eb",
22 * "name": "Gold",
23 * "description": "For expert gamers",
24 * "perks": [
25 * "Great value for your money",
26 * "Multi-user"
27 * ],
28 * "pricing": {
29 * "singlePaymentUnlimited": true,
30 * "price": {
31 * "value": "100",
32 * "currency": "USD"
33 * }
34 * },
35 * "primary": false,
36 * "_createdDate": "2020-12-21T15:13:06.202Z",
37 * "_updatedDate": "2020-12-30T10:14:03.202Z",
38 * "slug": "gold",
39 * "maxPurchasesPerBuyer": 1,
40 * "allowFutureStartDate": false,
41 * "buyerCanCancel": true
42 * },
43 * {
44 * "_id": "9e76b9dc-a3a6-3e25-ada5-a1ace10ccbeb",
45 * "name": "Gold Plus",
46 * "description": "Updated description for the original Gold plan",
47 * "perks": [
48 * "Multiplayer",
49 * "Multiple devices",
50 * "No ads",
51 * "Unlimited access"
52 * ],
53 * "pricing": {
54 * "subscription": {
55 * "cycleDuration": {
56 * "count": 1,
57 * "unit": "MONTH"
58 * },
59 * "cycleCount": 3
60 * },
61 * "price": {
62 * "value": "23",
63 * "currency": "USD"
64 * },
65 * "freeTrialDays": 7
66 * },
67 * "primary": false,
68 * "_createdDate": "2020-12-21T15:13:07.018Z",
69 * "_updatedDate": "2020-12-30T15:11:11.028Z",
70 * "slug": "gold-plus",
71 * "allowFutureStartDate": false,
72 * "buyerCanCancel": true,
73 * "termsAndConditions": ""
74 * },
75 * {
76 * "_id": "22f234bf-a3a6-7c32-abc1-88101ffcb2ef",
77 * "name": "Silver",
78 * "description": "For advanced gamers",
79 * "perks": [
80 * "Great avatar selection and background tunes",
81 * "All perks of Bronze membership"
82 * ],
83 * "pricing": {
84 * "singlePaymentForDuration": {
85 * "count": 3,
86 * "unit": "MONTH"
87 * },
88 * "price": {
89 * "value": "24",
90 * "currency": "USD"
91 * }
92 * },
93 * "primary": false,
94 * "_createdDate": "2020-12-21T15:13:10.327Z",
95 * "_updatedDate": "2020-12-30T15:11:11.117Z",
96 * "slug": "silver",
97 * "allowFutureStartDate": false,
98 * "buyerCanCancel": true,
99 * "termsAndConditions": ""
100 * }
101 * ]
102 * }
103 *
104 */