-
Notifications
You must be signed in to change notification settings - Fork 46
How To Book An Appointment
This will go much smoother if you've already activated your developer account / app. See getting started. The API testing site isn't kept up to date, I've found that there are features missing and that particular site is very error prone. The official MINDBODY docs can be found here (need to be logged in to view).
You will need to know several things about the client site before you can actually book an appointment, they are:
- location id
- staff id
- client id
- session type id
- user credentials (a staff member)
- username
- password
- site id
Lets start gathering all of the information stated above.
This will be the location you want the appointment booked at.
location = MindBody::Services::SiteService.get_locations.result[:locations].first
=> #<MindBody::Models::Location:0x000001020ab7e0
...
@id=1,
@image_url=nil,
@latitude=nil,
@longitude=nil,
...
This will be the staff member performing the appointment.
staff_member = MindBody::Services::StaffService.get_staff.result[:staff_members].first
=> #<MindBody::Models::Staff:0x0000010164ab70
...
@first_name="Jon",
@foreign_zip=nil,
@home_phone=nil,
@id=-5,
...
This will be the client booking the appointment. Note, that you can also glean the clients home_location
with this call, potentially making the above "Get Location" call unnecessary.
If you choose to provide search text you will need to provide user credentials as well.
params = {
"UserCredentials" => {
"Username" => "my_username",
"Password" => "my_password",
"SiteIDs" => { "int" => [000] } # Site id the staff member is at
},
"SearchText" => "Alex"
}
client = MindBody::Services::ClientService.get_clients(params).result[:clients]
=> #<MindBody::Models::Client:0x000001020b1780
...
@first_name="Alex",
@gender="Female",
@home_location=
#<MindBody::Models::Location:0x000001020b7838
...
@distance_in_miles=nil,
@facility_square_feet=nil,
@has_classes=false,
@has_site=nil,
@id=1,
...,
@home_phone=nil,
@id=100000009,
...
This will be the type of appointment booked. We will need to be sure and choose a session type that is available for booking.
session_type = MindBody::Services::SiteService.get_session_types.result[:session_types].first
=> #<MindBody::Models::SessionType:0x000001015a9ce8
@id=5,
@name=" Pilates Equipment Reformer Classes"
Put all of it together.
get_client_params = {
"UserCredentials" => {
"Username" => "my_username",
"Password" => "my_password",
"SiteIDs" => { "int" => [000] } # Site id the staff member is at
},
"SearchText" => "Alex"
}
client = MindBody::Services::ClientService.get_clients(get_client_params).result[:clients].first
location = MindBody::Services::SiteService.get_locations.result[:locations].first
staff_member = MindBody::Services::StaffService.get_staff.result[:staff_members].first
session_type = MindBody::Services::SiteService.get_session_types.result[:session_types].first
apppointment_params = {
"Appointment" => {
"Location" => { "ID" => location.id },
"StartDateTime" => DateTime.now,
"Staff" => { "ID" => staff_memeber.id },
"Client" => { "ID" => client.id },
"SessionType" => { "ID" => session_type.id }
}
}
MindBody::Services::AppointmentService.add_or_update_appointments(apppointment_params)
- Your
session_type
must be bookable. You can use theget_bookable_items
call to confirm this. - User credentials must be provided to add or update appointments AND they must have permission to do so.
-
Location
must be the first parameter set, otherwise you will receive a "LocationID must be provided" error. - In general hashes must match the SOAP structure exactly.
Please note that the above examples are haphazardly grabbing the first location, first staff, first client, and the first session type. You may have to implement more robust logic to grab appropriate locations, staff, clients, session types, etc.