I am trying to change the price of Pricing Plan in Wix Studio. Very simple code:
Back-end Code:
import { Permissions, webMethod } from 'wix-web-module';
import wixPricingPlansBackend from 'wix-pricing-plans-backend';
export const myUpdatePlanFunction = webMethod(Permissions.Anyone, async (planInfo) => {
console.log("Received planInfo in backend: ", planInfo)
let updatedPlan = await wixPricingPlansBackend.updatePlan(planInfo);
return updatedPlan
});
Front-end Code:
import wixWindowFrontend from 'wix-window-frontend';
import wixData from 'wix-data';
import { myGetPlanFunction } from 'backend/changePlanPrice.web.js';
import { myUpdatePlanFunction } from 'backend/changePlanPrice.web.js';
export async function changeButton_click(event) {
let newPrice = $w('#priceInput').value
const pricePlan2 = {
"_id": "7b8baa74-14ef-4a73-b6f9-8bdffb9bacfa",
"pricing": {
"price": {
"value": newPrice
},
},
}
myUpdatePlanFunction(pricePlan2)
.then(plan => {
// plan updated
console.log("Plan: ",plan)
})
.catch((error) => {
// plan not updated
const updateError = error;
});
}
The backend wixPricingPlansBackend.updatePlan is failing with limited error info - it just says FORBIDDEN. I am the logged in admin of the site so shouldn’t be a permissions issue (as I have “Managing Pricing Plans” permissions as the owner)…or am I missing something else here in how I’ve formatted the object. I’m puzzled.
The object is getting to the back-end, as the console.log works, but then immediately fails in both preview and on the live site.
According to the API, you only need the _id and the fields requiring update, but while troubleshooting, I built the whole object by pulling it down in the backend and modifying to remove fields that aren’t in the API, but I get the same error then.
Can anyone help?
Simon