The Webhook
When an Acuity Form is submitted, we get the session cookie from hubspot ("hubspotutk"), and send the user's email, id, and hubspot session cookie to my server at https://server.pappalar.do/adorn-nashville/cdat/catch, along with a site API key. After the data is POSTed to the server, we redirect to the booking confirmation page.The Controller (AdornNashvilleController)
1. We create a database record for the appointment if one doesn't already exist.2. We make a request to get the full details of the appointment from Acuity's API. (getAcuity function in AdornNashvilleHelper)
3. We set the label to "Scheduled" unless the Acuity label is something different.
4. We add all the Appointment Details to the database record. (addBridalApptDetails function in AdornNashvilleHelper)
4.1. Just a loop through all the fields trying to match the field ID to the correct database column.
5. If there is no HubSpot Contact ID in the database record (which should happen like 98% of the time), we submit the appointment. (submitBridalAppt in AdornNashvilleHelper).
5.1 We submit to one of the following HubSpot forms based on the appointment type:
- Acuity Leads - First Time Bridal Appointments
- Acuity Leads - Ready to Wear Appointments
- Acuity Leads - Wait List
- Acuity Leads - Pickup Appointment
- Acuity Leads - Preservation Appointment
- Acuity Leads - Veil & Accessory Appointment
- Acuity Leads - Follow Up Bridal Appointment
6. We wait 5 seconds and then search for the contact in HubSpot by email (lookupHubSpotContactByEmail function in AdornNashvilleHelper), in order to associate the contact ID with the database record. If we couldn't find the user (should be very uncommon but here as a safeguard), we create a new contact. (createHubSpotContactV3 in AdornNashvilleHelper).
7. We add the engagement ("Note") to the HubSpot Contact (createEngagementInHubSpot in AdornNashvilleHelper).