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()
.
Property | Filters | Examples |
---|---|---|
_id | eq() , ne() , hasSome() | hasSome("_id", ["46ce4cd4-46ff-13a1-43ac-02fd4f0f3209", "94ce4cd4-46cc-20c3-4c7a-03fd4f0f3306"]) |
primary | eq() , ne() , ascending() , descending() | eq("primary",true) |
slug | eq() , ne() , startsWith() , endsWith() , contains() , ascending() , descending() | eq("gold") |
_createdDate | eq() , ne() , gt() , ge() , lt() , le() , between() , ascending() , descending() | lt("_createdDate", "2020-04-27T10:00:00.000Z") |
_updatedDate | eq() , 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 thesetTimeout()
function to delay querying following any changes to your plan data. Thefind()
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?
1import wixPricingPlansBackend from 'wix-pricing-plans-backend';23export function myQueryPublicPlansFunction() {4 return wixPricingPlansBackend.queryPublicPlans()5 .find()6 .then((result) => {7 console.log(result);8 })9 .catch((error) => {10 console.error(error);11 });12}1314// Query results15/*16 * {17 * "items": [18 * {19 * "_id": "3fb6a3c8-988b-7896-04bd-6c69ae0b18eb",20 * "name": "Gold",21 * "description": "For expert gamers",22 * "perks": [23 * "Great value for your money",24 * "Multi-user"25 * ],26 * "pricing": {27 * "singlePaymentUnlimited": true,28 * "price": {29 * "value": "100",30 * "currency": "USD"31 * }32 * },33 * "primary": false,34 * "_createdDate": "2020-12-21T15:13:06.202Z",35 * "_updatedDate": "2020-12-30T17:10:01.202Z",36 * "slug": "gold",37 * "maxPurchasesPerBuyer": 1,38 * "allowFutureStartDate": false,39 * "buyerCanCancel": true40 * },41 * {42 * "_id": "9e76b9dc-a3a6-3e25-ada5-a1ace10ccbeb",43 * "name": "Gold Plus",44 * "description": "Updated description for the original Gold plan",45 * "perks": [46 * "Multiplayer",47 * "Multiple devices",48 * "No ads",49 * "Unlimited access"50 * ],51 * "pricing": {52 * "subscription": {53 * "cycleDuration": {54 * "count": 1,55 * "unit": "MONTH"56 * },57 * "cycleCount": 358 * },59 * "price": {60 * "value": "23",61 * "currency": "USD"62 * },63 * "freeTrialDays": 764 * },65 * "primary": false,66 * "_createdDate": "2020-12-21T15:14:08.018Z",67 * "_updatedDate": "2020-12-30T15:13:07.018Z",68 * "slug": "gold-plus",69 * "allowFutureStartDate": false,70 * "buyerCanCancel": true,71 * "termsAndConditions": ""72 * },73 * {74 * "_id": "22f234bf-a3a6-7c32-abc1-88101ffcb2ef",75 * "name": "Silver",76 * "description": "For advanced gamers",77 * "perks": [78 * "Great avatar selection and background tunes",79 * "All perks of Bronze membership"80 * ],81 * "pricing": {82 * "singlePaymentForDuration": {83 * "count": 3,84 * "unit": "MONTH"85 * },86 * "price": {87 * "value": "24",88 * "currency": "USD"89 * }90 * },91 * "primary": false,92 * "_createdDate": "2020-12-21T15:13:10.327Z",93 * "_updatedDate": "2020-12-30T19:02:13.327Z",94 * "slug": "silver",95 * "allowFutureStartDate": false,96 * "buyerCanCancel": true,97 * "termsAndConditions": ""98 * }99 * ]100 * }101 */
1import wixPricingPlansBackend from 'wix-pricing-plans-backend';23export function myQueryPublicPlansFunction() {4 return wixPricingPlansBackend.queryPublicPlans()5 .lt("_createdDate", "2021-01-15T10:00:00.000Z")6 .find()7 .then((result) => {8 console.log(result);9 })10 .catch((error) => {11 console.error(error);12 });13}1415// Query results16/*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-30T10:14:03.202Z",37 * "slug": "gold",38 * "maxPurchasesPerBuyer": 1,39 * "allowFutureStartDate": false,40 * "buyerCanCancel": true41 * },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": 359 * },60 * "price": {61 * "value": "23",62 * "currency": "USD"63 * },64 * "freeTrialDays": 765 * },66 * "primary": false,67 * "_createdDate": "2020-12-21T15:13:07.018Z",68 * "_updatedDate": "2020-12-30T15:11:11.028Z",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-30T15:11:11.117Z",95 * "slug": "silver",96 * "allowFutureStartDate": false,97 * "buyerCanCancel": true,98 * "termsAndConditions": ""99 * }100 * ]101 * }102 *103 */