Question:
Why can’t I use contactId to link a new booking (via createBooking) to a contact?
Product:
Wix Bookings - createBooking API.
What are you trying to achieve:
I am setting up Wix Bookings for a children’s gym. Parents make bookings for their children. So my workflow is:
- Parent selects the course.
- Check availability and prompt the parent to login (or create a new login).
- Parent provides first name and last name of the child they are making the booking for. Because the children range in age from 2 to 15 most of them do not have their own email address - so the parent’s email address is used.
- Search for an existing contact (queryContact) based on first name, last name, and email and if no contact exists create a new one (createContact).
- The contactId is passed in createBooking to create the booking for the child.
What have you already tried:
The expected behavior is that the booking would be linked to the contactId - however this is not the case. If firstName, lastName, and email are passed a booking is created for the child but with no link to the contact. Same outcome if contactId is also passed. If only contactId is passed the resulting booking is linked to the loggedin member.
Additional information:
This is an example of the booking object passed to createBooking:
{
"totalParticipants": "1",
"bookingSource": {
"actor": "CUSTOMER",
"platform": "WEB"
},
"contactDetails": {
"firstName": "Linda",
"lastName": "Wilson",
"email": "linda_wilson9999@gmail.com",
"contactId": "0e4d2cfe-c092-481f-88fb-9083d42fb102"
},
"bookedEntity": {
"schedule": {
"scheduleId": "04dc3b61-1e26-4379-b084-8228b1d713f0",
"serviceId": "54bfcb46-3e8d-4e0a-a204-fc6a2636199b",
"location": {
"locationType": "OWNER_BUSINESS"
},
"firstSessionStart": "Thu Jan 04 2024 15:00:00 GMT+1300 (New Zealand Daylight Time)",
"lastSessionEnd": "Thu Apr 04 2024 15:45:00 GMT+1300 (New Zealand Daylight Time)",
"resource": {
"id": "76570209-101f-409b-af97-b445bdb63125"
}
},
"tags": [
"COURSE"
]
},
"flowControlSettings": {
"skipAvailabilityValidation": false,
"skipBusinessConfirmation": false,
"skipSelectedPaymentOptionValidation": false
}
}
I suspect that the matching logic is only using email address, ignoring the contactId passed. This will not work for my use case as the child has the same email address as the parent.
If this is not a bug - is there another way to achieve the same outcome (booking is linked to the child contactId)?
Thanks for your help!
I know createBooking is in Developer Preview - if any of the Wix devs are monitoring this channel…it would be amazing if the contact matching logic in contactDetails could be changed to: email + firstName + lastName OR contactId.
This would solve for my use case (which I expect would be very common)
Hey man, I hope they solve your issue. On a sidenote, I’m having a problem when creating a booking and passing the scheduleId, I always get no available spots in schedule. Can you tell me how did you manager to fix that?
So in my case I am presenting courses in a repeater with a ‘Book’ button for each repeater item. Once a book button is clicked I use getServiceAvailability to determine if the course has slots available - if so prompt the member to login (or create a new login) then continue to create the booking. If there is no availability I display a message for 3 seconds and nothing else happens. To query availability for a course I use getServiceAvailability (requires the Service Id) - which returns available slots from todays date forward by default. My code looks something like this:
import { getServiceAvailability } from 'wix-bookings';
import { authentication, currentMember } from 'wix-members';
let clickedItemData;
let bookingSlot;
let loggedInMember;
async function bookButton_click(event) {
// Get the Service id from the repeater item selected
const data = $w("#classRepeater").data;
clickedItemData = data.find(item => item._id === event.context.itemId);
// Check if there are slots available for the selected class
const availability = await getServiceAvailability(clickedItemData._id)
bookingSlot = availability.slots[0];
if (bookingSlot.remainingSpots <= 0) {
// If there are no available slots display class full message
$w('#coursesMessage').show()
$w('#coursesMessage').text = "Sorry - this class is full. Please contact us for assistance.";
setTimeout(function () { $w('#coursesMessage').hide() }, 3000);
} else {
// if there is availability check if member is logged in and if not prompt login - then continue to process the booking
loggedInMember = await currentMember.getMember()
if (typeof loggedInMember !== 'undefined') {
processBooking()
} else {
loggedInMember = await authentication.promptLogin()
if (typeof loggedInMember !== 'undefined') {
processBooking()
}
}
}
}
Hope that helps…
1 Like
So I’m super happy to discover that the linking of a contact to a booking (using createBooking) now uses either (firstName, lastName, email) OR (firstName, lastName, contactId) and is working perfectly for my use case. This enables setting up parent/child relationships and enables a workflow whereby a booking can be created by the parent for a child who has the same email address as the parent.
Most awesome!
BUT - now I have the challenge that createCheckout breaks the booking link to the contact established by createBooking and creates a link to the member paying for the booking.
Is there a way to create the order/checkout and maintain the integrity of the booking linked to the contact linked using createBooking?
Thanks!