Unable to createPlan()

I have an admin page with a submit button for creating a new pricing plan.

  • when trying to create a new pricing plan with createPlan() the following object, I get "FORBIDDEN’ error, although the user is the site owner, and although I used the objPlan from Velo reference:

const objPlan = {
“name”: “Gold”,
“description”: “Gold membership to the MyGame World of Online Gaming”,
“perks”: [
“Multiplayer”,
“Multiple devices”,
“No ads”,
“Unlimited access”
],
“pricing”: {
“price”: {
“value”: “10.00”,
“currency”: “ILS”
},
“singlePaymentUnlimited”: true
},
“public”: true,
“maxPurchasesPerBuyer”: 1,
“allowFutureStartDate”: true,
“buyerCanCancel”: true,
“termsAndConditions”: “No sharing access with others!”
}

When trying to create a plan with my plan object, for defining a monthly recurrent plan, I get the error details":**{“applicationError”:{“description”:“Bad Request”,“code”:“BAD_REQUEST”,“data”:{}}}}

const objPlan = {
“name”: planName,
“description”: “תשלום מתחדש אוטומטית”,
“perks”: ,
“pricing”: {
“price”: {
“value”: String(apartment.totalPay) + “.00”
},
“subscription”: { “cycleDuration”: 1, “count”: “MONTH” },
“cycleCount”: 0
},
“public”: true,
“maxPurchasesPerBuyer”: 1,
“allowFutureStartDate”: true,
“buyerCanCancel”: true,
“termsAndConditions”: “No sharing access with others!”
}

Does someone has any insights for me???
Thanks a lot :pray: :pray: :pray:

Even if user is admin I think you will need to elevate the permissions for the function to let it run successfully. If you are getting 403 (FORBIDDEN) error it also means there is a permission problem.

Can you try to elevate the permissions like that:

import { plans } from 'wix-pricing-plans.v2';
import { elevate } from 'wix-auth';

const elevatedCreatePlan = elevate(plans.createPlan);

// your createPlan code...

I think this one should fix the permission problem. You can read the full example here:

1 Like

Thank you LoeiX!
Your advise was perfect!! :star_struck:

Is everything good now?