Getting BOOKINGS_SYSTEM_ERROR when trying to checkOutBooking in wixBooking

I was trying to replicate the functionality mentioned in the below two videos for creating a custom booking system.
https://www.youtube.com/watch?v=lEEIaJyKzM8
https://www.youtube.com/watch?v=_hKsMICCfAM

There are two issues that I am getting while trying to follow the code in the videos.
1. When trying to add the slot._id to the slotPicker dropdown, wix gives error saying that the value of the dropdown exceeds 400 chars. The slot._id I am getting from the API is more than 400 chars. Eg : 4XH3LWgKG5txVlW2EDckWeLceXMrFoQG3X11PHA2hGmTHELEwRaWLXF9JzhI1w2GB5eK6tgXz2EZT3FbXFGfCypATbruniAzL235GS6a9eDz7kTJCzI3m3EWO3XoYHTQi2bUtfe3BW7u488dnb3yhEYyUNfb8RDJdNxmlYlBVHLUrpNjZonqNSKczIGvZ27cV6hJHFZkkBE68EbuizBYCLkazLBQHZ2Y0BEc5KfEe9xEkoJwlNQhbVjLZ4w6l4Abf5NLHIZjqrVMY5KCVw092pk4Hhyu4A5TVgcWdOvz4hCevSj0XcMk61hREBMOoVl7kHMftRj55luEu7zGuGgIAIVYqdZmAY6wD4DhNiCUAOj8YSecJlwRmgbdBeHaRqq5urv9tkPzt628OEiaNhuClKf00iyrssv1xgWQn

I tried to work around this issue by storing the slot Id in another variable.

2. When trying to checkOutBooking, it gives the below error.
{code: 500, message: “BOOKINGS_SYSTEM_ERROR”}

Below is the code I am using. This is still development…hence there is some hard coding.

// For full API documentation, including code examples, visit https://wix.to/94BuAAs
import wixUsers from 'wix-users';
import wixBookings from 'wix-bookings';
import wixData from 'wix-data';

const serviceId = 'e48bff50-7e67-4c57-bcfe-a6385daddf76';

let slotsMap = {};
let currentUserEmail = "";
let slotIDmap = [];
$w.onReady(function() {

  populateExpertList();
  $w('#datePicker').disable();
  $w('#slotPicker').disable();
  let selectedExpert = "";

  $w('#expertSelector').onChange((event, $w) => {
    selectedExpert = $w('#expertSelector').value;
    console.log("Selected Expert = " + selectedExpert);
    $w('#datePicker').enable();
    $w('#datePicker').selectedIndex = undefined;
    $w('#slotPicker').disable();
  });

  let user = wixUsers.currentUser;
  user.getEmail()
    .then((email) => {
      let userEmail = email; // "user@something.com"
      currentUserEmail = email
      $w('#loggedInUserName').text = userEmail;
    });

  const today = new Date();
  const daysOfTheWeek = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
  $w('#datePicker').options = getWeekDays(today).map(day => {
    return {
      label: `${daysOfTheWeek[day.date.getDay()]} ${day.date.toLocaleDateString("en-GB")}`,
      value: day.date.toISOString()
    }
  });
  $w('#datePicker').onChange((event, $w) => {
    const selectedDate = new Date(event.target.value);
    findAvailableSlots(selectedDate, selectedExpert);
  });

  $w('#submitButton').onClick(() => validateAndSubmitForm());

});
//=============================================================
async function findAvailableSlots(dateString, selectedExpert) {
  slotsMap = {};
  const startDateTime = getMidnight(dateString);
  const endDateTime = getNextMidnight(dateString);
  const options = {
    startDateTime,
    endDateTime
  }

  const availableSlots = await getServiceAvailableSlots(serviceId, options, selectedExpert);
  console.log("Number of availableSlots= " + availableSlots.length);

  for (let i = 0; i < availableSlots.length; i++) {
    slotIDmap[i] = availableSlots[i]._id;
  }
  console.log("MAP=>" + slotIDmap);
  let index = -1;
  if (availableSlots.length === 0) {
    $w('#slotPicker').options = [];
    $w('#slotPicker').placeholder = 'No Slots available for this day';
    $w('#slotPicker').selectedIndex = undefined;
    $w('#slotPicker').disable();
  } else {
    $w('#slotPicker').options = availableSlots.map(slot => {
      slotsMap[slot._id] = slot;
      let startTime = slot.startDateTime;
      let timeString = getTimeOfDay(startTime);
      console.log("timeString = " + timeString);
      console.log("slot._id = " + slot._id);
      index = index + 1;
      console.log("index = >" + index);
      console.log("------------------")
      return {
        label: timeString,
        value: index + ""
      }
    });
    $w('#slotPicker').placeholder = 'Pick a time slot';
    $w('#slotPicker').selectedIndex = undefined;
    $w('#slotPicker').enable();
  }
}
//======================================================
async function validateAndSubmitForm() {

  const formFields = ['datePicker', 'slotPicker', 'expertSelector']; //Add expert picker as well.
  console.log("selected index of slot =>" + $w('#slotPicker').value);
  const selectedSlot = slotsMap[slotIDmap[$w('#slotPicker').value]];
  console.log("selected slot =>" + selectedSlot.staffMemberId);
  console.log("selected slot =>" + selectedSlot._id);
  console.log("selected slot serviceId =>" + selectedSlot.serviceId);

  const service = await (getService(selectedSlot.serviceId));
  let bookingFormFields = [{
      _id: getFieldId(service, "Name"),
      value: "Some Name"
    },
    {
      _id: getFieldId(service, "Email"),
      value: currentUserEmail
    },
    {
      _id: getFieldId(service, "Phone Number"),
      value: "121212121212"
    }
  ];

  console.log("bookingFormFields =>" + bookingFormFields);
  console.log("selectedSlot =>" + selectedSlot);

  const bookingInfo = {
    "slot": selectedSlot,
    "formFields": bookingFormFields
  };
  const bookingResponse = await wixBookings.checkoutBooking(bookingInfo);
  console.log("Bookng Status =>" + bookingResponse.status);
}
//==============================================================
async function populateExpertList() {
  await wixData.query("Bookings/Staff")
    .find()
    .then((results) => {
      $w('#expertSelector').options = results.items.map(item => {
        return {
          label: item.name,
          value: item._id
        }
      });
    });
  $w('#expertSelector').placeholder = 'Pick an Expert First';
}
//==============================================================
async function getServiceAvailableSlots(requestedServiceId, options = {}, selectedExpert) {
  let availableSlots = (await wixBookings.getServiceAvailability(requestedServiceId, options)).slots;
  availableSlots = availableSlots.filter(slot => slot.staffMemberId === selectedExpert);
  return availableSlots;
}
//=============================================================
function getMidnight(date) {
  let midnight = new Date(date);
  midnight.setHours(0, 0, 0, 0);
  return midnight;
}
//============================================================
function getNextMidnight(date) {
  let midnight = new Date(date);
  midnight.setHours(24, 0, 0, 0);
  return midnight;
}
//============================================================
function getWeekDays(startDate) {
  let weekDays = [];
  let current = getMidnight(startDate);

  for (let i = 0; i < 14; i++) {
    weekDays.push({
      _id: "day" + i,
      date: current
    });
    current = getNextMidnight(current);
  }
  return weekDays;
}
//==========================================================
function getTimeOfDay(date) {
  return date.toLocaleTimeString([], {
    hour: '2-digit',
    minute: '2-digit'
  }).toLowerCase();
}
//==========================================================
function getService(id) {
  return wixData.get("Bookings/Services", id);
}
//==========================================================
function getFieldId(service, label) {
  return service.form.fields.filter(field => field.label === label)[0]._id;
}

You would be much better suited if you actually worked with the proper example as shown here and not just go by the youtube tutorial.

How to Create a Quick-Booking Form with the Wix Bookings API
https://www.wix.com/corvid/tutorial/how-to-create-a-quick-booking-form-with-the-wix-bookings-api
https://www.wix.com/corvid/example/quick-book-and-pending-appointments

In the second link to the full example, you will be able to open up the tutorial in your own editor and have the page fully laid out with all elements and code added to the page for you already.

How to Create an Admin Page to Manage Booking Requests
https://www.wix.com/corvid/tutorial/how-to-create-an-admin-page-to-manage-booking-requests
https://www.wix.com/corvid/reference/wix-bookings.html

Finally, have a look at the Bookings section on the Examples page for this forum which will give you a few more examples that you can open fully in your editor etc.
https://www.wix.com/corvid/examples

Thanks for the response. But there is a slight problem.
The example at https://www.wix.com/corvid/example/quick-book-and-pending-appointments does not have the code for this page. The page displays code for the admin page, which is the next step. Can I get the code for the quick book page/LightBox. The code does not appear when I open the example site in Editor as well. There is code for the admin page only.

Also I am pretty sure that the code that I have written is similar to what is there in the youtube video since it works for the most part. The place where I am getting an error is when I am trying to check Out the booking. I am able to get the slot from the bookings API. I am able to filter the slots based on expert. I am able to select the slot from the UI. All this works. What does not work is when I try to actually book the appointment/slot. I am getting WIX API error. If you can guide me on why WIX does not like what I am sending, maybe I will be able to get it working.

If you can help check why am I getting a long string from slot._id and then why am I getting the BOOKINGS_SYSTEM_ERROR, it will be of great help!.

Thanks

Yes looking at it myself, I can see that they must have obviously updated the tutorials for this option and not put the correct tutorials onto the Wix Support youtube pages, however it is correct if you go through the Wix Corvid Forum examples page and go through the Bookings tab.

https://www.wix.com/corvid/examples - go here and then choose Bookings in the menu choice.

If you look at the Bookings example called Timetable (let customers book sessions using a class schedule), then that example will show you the full code needed, although it won’t be exactly the same as the tutorial shown in the existing Wix youtube video.

So, unfortunately, you will have to look at redoing your website to match the tutorial and code if you wish to use that instead.

The existing video and tutorial for the admin part you can still use as that is the second example down in the Bookings examples list.

I will mention this to the Admin of this forum and see if they can pass it onto the relevant Wix department to get it corrected as the youtube videos are dated from April 8th and obviously haven’t been updated when the example was changed for the Corvid example itself.

Thanks for mentioning it as I didn’t check it myself as I was just assuming that they would all be correct, so apologies on behalf of Wix that this has caught you out and cross fingers that they correct it soon or they at least put the code for that youtube example back so that it can be used instead of having to go back and forth through the video.

Just to update, if you go through the Wix Bookings with Corvid section.
https://support.wix.com/en/corvid-by-wix/wix-bookings-with-corvid

Then the link here will show you the right code that matches up with the Wix Corvid example.
Corvid Tutorial: Creating a Bookings Timetable

Thanks for the update. However as I mentioned, I have got the code working for the most part. It is able to fetch the slot from the bookings API, it is able to filter the slots by the available staff. I am not able to checkOut the booking or basically confirm the booking. I am getting BOOKINGS_SYSTEM_ERROR from wix. When I dug a little deeper, the error is coming from the Wix Bookings API. The wix code tries to call the WIX API at /booking and the response from that API is a 500 Internal Server Error. Can you please have someone in the product team to look at this issue. I can provide any additional details as needed.

When trying to do the booking via the site, if I take a look at the Browser Console and Network, I see that the booking API call returns with 500 Internal Server Error. Got the same when I tried to call the API URL from Postman and passing the same header authorization as in the actual site. Hopefully, this helps the Wix Technical team to diagnose either what am I doing wrong or if there is a problem in the site.

Did some more digging on this. All of my services which I am trying to book through the API code are part of a Paid Plan. I created another service and did not tie to any Paid Plan and I was able to book the session. Did not get any error. But the errors come for all the services which are part of a Paid Plan. The payload for both is the same, except the slot._id.

Payload which works. This is for a service which is not part of a paid plan.

{
  "slotId": "4XH3LWgKG5txVlW2EDckWeLceXMrFoQG3X11PHA2hHXOBXkTawkuAOrLTNmMsNrHKXtLlJ39r6j4Z7tqDmXV9uM2cropBTvm1jwSaD1HhOLHQLt8aDTcUxj6doFaxKbPBmIAwCfiOG9CWdix3kQhwuw16VWZsDukTWKanL0AZyv1KIxCWBnSADQ3apbUYGYSIBagfbWY79S0Eru8hyFTalGalpoc6WVMMYRUgabUSwi1R8v27SSHkiKsGNrD8acvL25g3weN4kLd3hr8qxQpwcV55gvLx2jrFL3Wu7Y6hHljZP0zlJh6T7Bf0MyNtiX9IyidxBM7A7IzNLg22khWaR5qQabeTC8lqorrpPEEdH72lZJ19LVzge175hdWr8sWIled4Ikp3HqlsTDIqoWt1A3UHor9N6giksemD",
  "bookingInfo": {
    "id": "00000000-0000-0000-0000-000000000000",
    "fields": [{
      "id": "00000000-0000-0000-0000-000000000001",
      "value": "Some Name OK"
    }, {
      "id": "00000000-0000-0000-0000-000000000002",
      "value": "some.name@gmail.com"
    }, {
      "id": "00000000-0000-0000-0000-000000000003",
      "value": "112233445566"
    }, {
      "id": "00000000-0000-0000-0000-000000000007",
      "value": "1"
    }]
  }
}

Payload which gives error. Service part of a Paid Plan.

{
  "slotId": "4XH3LWgKG5txVlW2EDckWeLceXMrFoQG3X11PHA2glLB7vpn8zWYgC3OEJSgotkiyD7fBzkZ2iKHwvi3ayLpoiP1F5gyDq6IFgugHqg2c05GBzE32lpqcjPcLmIflS01SvrqYEvaLBbzCovQwMiIpDjdXqLazxVWIIQJZIhLk9UlFbNfLq5UWzGOakKDZWiGUPOeBznqnrzZdUj37uGRCvPUtZp2m3eGuHGjpf0vowUoegLeCezvUcmjn7ef1mHNmtfP1s7CXKYTuMUGGEXmqw0d7CySv3RIz9rUid7xsiImzlEfXmZLikwA7xNVmmWezMLtmlfsHaRPMOvTahs5hjg86vYEr4aNQUO2bpLgdqS9WokewF2MPTfvHKuIDlA2sK8cXx2akpNAUboIjJI6cQKcrsO2FzhGYs3un",
  "bookingInfo": {
    "id": "00000000-0000-0000-0000-000000000000",
    "fields": [{
      "id": "00000000-0000-0000-0000-000000000001",
      "value": "Some Name Error"
    }, {
      "id": "00000000-0000-0000-0000-000000000002",
      "value": "some.name@gmail.com"
    }, {
      "id": "00000000-0000-0000-0000-000000000003",
      "value": "112233445566"
    }, {
      "id": "00000000-0000-0000-0000-000000000007",
      "value": "1"
    }]
  }
}

I think that there might be an issue on Wix processing side where it is not able to handle the booking for a service which is part of a Paid Plan. Can someone from Wix team confirm this and let me know if there is a workaround or a fix.

I am having a very similar problem. All my Paid Services receive a BOOKINGS_SYSTEM_ERROR. The Free services work fine. I did upgrade the booking app and now I am having problems… Any help would be greatly appriciated

Any ideas on what is going on? Ever since the Bookings app was updated I am unable to book any Paid Services via the API. I receive the BOOKINGS_SYSTEM_ERROR message when i issue wixBookings.checkoutBooking(bookingInfo, paymentOptions command. In preview mode I get a “confirmed” response without going to payment page (this might be OK), but on my live site I get the BOOKINGS_SYSTEM_ERROR message and am never passed to the payment pages. Again this was working fine a few weeks ago, prior to updating the bookings app. Free services work fine! I am following the CORVID example as mentioned above. I would think that if this was system wide you would be getting a lot more complaints. Would really appreciate any help! Thanks

@givemeawhisky - I am having the same problem - (some additional details below). Any ideas on what the problem may be? Thanks so much!

For me there is a quite similar problem (you can have a look here: https://www.wix.com/corvid/forum/community-discussion/wix-bookings-api-paymenttype-wixpay-offline-not-working-in-checkoutbooking-function )
The FREE Services are working without any issues, but I´m unable to book paid Services (paymentType = “OFFLINE”) with the Wix-Booking API!
In every test case, the booking API provides an “500 Internal Server Error”:

Could this be an Wix-Booking issue? I would really appreciate any help, because I’ve tried everything I could find in the API Reference, Docs, Posts, Examples etc.
Thanks, Tom

This issue continues to go on with no response from Corvid… Below is my “form fields” and “slot” info along with the “500” error message. The key to this error is that “Free Services” work fine, and any “Paid Service” receives this error. It is quite frustrating that we are seeing nothing from Corvid on this issue. If we are not calling the API correctly, please let us know. If the problem is with the API, again, please let us know. (Luckily, for me, I have not put my site in production yet, but I am losing confidence that the Booking App (with its API) is a good solution.) Any response from Corvid would be greatly appreciated…

ObjectformFields: Array(4)
0:{_id: “b7b714ed-f7b3-4bc4-b562-84d6d47741b4”, value: “xxxxx@comcast.net”}
1: {_id: “1afdcb80-1e84-45f3-aecb-b844bf8504e8”, value: “804-xxx-xxxx, 804-xxx-xxxx”}
2: {id: “37a0448e-eff5-48c3-b8a8-4dac5ec725fd”, value: “Rocky XXXXXX”}
3: {id: “e84bc883-7663-4c39-a940-56c9155bb50a”, value: “Comet”}length: 4__proto
:

Array(0)slot:
bookable: undefined
capacity: 11
constraints: undefinedend
DateTime: Wed Feb 26 2020 19:00:00 GMT-0500 (Eastern Standard Time) {}
remainingSpots: 8
serviceId: “09337753-38a4-4d69-993e-a0e4dc6b03fc”
staffMemberId: “f8279117-1f7b-4ec9-8427-9d417da377c9”
startDateTime: Wed Jan 08 2020 18:00:00 GMT-0500 (Eastern Standard Time) {}
_id: “lVpmmjufa6ayxC3FfTkdAZG8QEmULA0jjcaKWdqkOwMYyiY9Kd1iOhJqw1d1cRuz8BcTGn5fXJVMmYvY7qYGTzukd2eACqH84B47WH”

code: 500message: "BOOKINGS_SYSTEM_ERROR"proto: Object

Just pushing the issue.
I still got the Error 500 and it´s a bit frustrating that there is no assistance from wix corvid or the wix booking development.
The wix support just refers me to this forum… :-/

Hi guys,
trying to getCheckoutOptions from the wixBooking API.
When customer has chosen his options they get redirected to a lightbox with an overview of their data. In this lightbox I try to get the results for the getCheckoutOptions function. Using dataObject to pass items between the lightbox and the page. In test mode no console.log(results). When runing in google javascript console error 500 BOOKINGS_SYSTEM_ERROR appears… If anyone could point me in the right direction or if it’s a wix/corvid issue, so I can try to work around it, that would be freaking awesome! Thanks
Here is the code regarding getCheckoutOptions:

import wixWindow from ‘wix-window’;
import wixBookings from ‘wix-bookings’;

$w.onReady( function () {

**let**  received = wixWindow.lightbox.getContext(); 

**let**  slot = received.slot; 
**let**  slotId = slot._id; 

console.log(slotId) /* = 4XH3LWgKG5txVlW2EDckWeLceXMrFoQG3X11PHA2gjPhFEuPFClGAV605vbIu5cOw3UY49almzCXzxtEt59mMxfyXBOHSKQn1RLBlSO1ezTmk7dxihSWPpXNd583aVpLBQ5jGenxwyHrphgKMflWSujzxzQMmqn7uIDKV6Frq8HFmINfSKh6lzGmL8Ud93gDkyJOjd0YAgVL024prO1rwU4Q9R8KtJJMPA7XjDASu02wpOTWt6njWs2XJ0vUNAiFCFgjj1lu8ObMnQTQwRhyFDXbuUR973735DzWHQHpP2eEscN3ObJw7gZcNdJPeKLpC51JiU1ATEpIGCSmRVZ2cNrxO3w21UyyKraNVc20SO6OHLQ6usoQYSqtHHy9fEFxT1b1jgLF6cBEcBn1iYlbLmRd18y7qKIrSdKBR */ 

**let**  serviceId = slot.serviceId; 

$w("#payButton").onClick(() => { 

    wixBookings.getCheckoutOptions(slotId) 
        .then((results) => { 
        console.log(results) 
        let firstOptionType = results[0].type; 
        console.log(firstOptionType) 
    }); 
}); 

});

So I made a new site, just to test the wixBooking API. I am doing something wrong or I don’t know… The simplest functions don’t seem to work. I’ve written this code just to see if I could get checkoutOptions, still same 500 error. And then I deleted the checkoutOptions function and added checkoutBooking to try and create an appointment. In test mode it doesn’t work. No error messages but also no booking confirmation. in live version Javascript console gives the following error:

Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

Here is the code:

import wixData from ‘wix-data’;
import wixBookings from ‘wix-bookings’;

let serviceId;
$w.onReady(() => {
wixData.query(“Bookings/Services”)
.find()
.then((results) => {
serviceId = results.items[0]._id
wixBookings.getServiceAvailability(serviceId)
.then((slots) => {
let firstSlot = slots.slots[0]
let slotId = firstSlot._id

                **let**  formFieldValues = [{ 
                    "_id": "1aca22f0-ab22-4777-933f-76bd836a003e", 
                    "value":  ["email@email.com"]("email@email.com"

)
}, {
“_id”: “bde0e106-5127-4dee-8bb0-35e472822b54”,
“value”: “kikolator pipas”
}]

let bookingInfo = {
“slot”: slotId,
“formFields”: formFieldValues
};

let options = {
“paymentType”: “wixPay_Offline”,
};

                wixBookings.checkoutBooking(bookingInfo, options) 
                    .then((result) => { 
                        **let**  id = result.bookingId; 
                        **let**  status = result.status; 
                        console.log(id) 
                        console.log(status) 
                    }); 
            }) 
    }) 

})

Has this been resolved? I’m having the same issue :confused: If not, does anyone have a workaround for how to make a booking using a custom booking process?

All of the sudden my booking also started to give this error. It was working before.

@raltimore Did you solve this? I’m having the same issue. It was working fine and all of the sudden it gives me the same error

Hi everyone,
Thanks for letting us know. We’re currently looking into the issue and will update the thread when it’s resolved.