Introduction
HeavySet Tech customers looking to move beyond the standard web form iframe application can turn to the HeavySet Tech API for a more customized solution in capturing leads and scheduling appointments. This API facilitates a higher degree of flexibility and control over the user interface and interaction experience. In this guide, we provide a step-by-step walkthrough on utilizing the API endpoints to efficiently handle leads and appointments. Examples throughout the guide will be provided in curl and JavaScript.
Step 1: Authentication - Retrieve One Time Token
Endpoint: https://api.heavyset.tech/api/v1/appointment/page/auth
First things first, authentication. In the server-side environment, initiate the process by calling the above endpoint to exchange an access token for a one-time token. This critical step ensures secure access to further API functionalities.
curl -X POST "https://api.heavyset.tech/api/v1/appointment/page/auth" \
-H "Content-Type: application/json" \
-d '{
"token": "yourTokenHere",
"source": "exampleSource",
"sourceType": "exampleSourceType"
}'
This returns a oneTimeToken required for the next step.
Step 2: Retrieve JWT Token for Frontend Calls
Endpoint: https://api.heavyset.tech/api/v1/appointment/page/auth/one-time
With the oneTimeToken in hand, move to the frontend and call the above endpoint to exchange it for a JWT token, the golden key to the remaining API endpoints.
curl -X POST 'https://api.heavyset.tech/api/v1/appointment/page/auth/one-time' \
-H 'Content-Type: application/json' \
-d '{
"oneTimeToken": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx",
"source": "",
"sourceUrl": "https://example.com",
"sourceType": ""
}'
Step 3: Capture Lead Email
Endpoint: https://api.heavyset.tech/api/v1/appointment/page/api/lead/email
As users interact with your website, capture a leads email and use the above endpoint to store the email for this session.
async function submitEmail(jwtToken, email) {
const url = 'https://api.heavyset.tech/api/v1/appointment/page/api/lead/email';
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${jwtToken}`
},
body: JSON.stringify({ email })
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
console.log(data);
} catch (error) {
console.error('Error:', error);
}
}
// Example Usage
submitEmail('JWT Token Here', '[email protected]');
Step 4: Gather Detailed Lead Information
Endpoint: https://api.heavyset.tech/api/v1/appointment/page/api/lead
Progress the interaction by collecting detailed information such as the user’s name, address, ZIP code, and phone number through another form and push this data using the above endpoint.
async function sendPostRequest(jwtToken, name, address, zipCode, phone) {
// Replace with actual values
const url = 'https://api.heavyset.tech/api/v1/appointment/page/api/lead';
const body = { name, address, zipCode, phone };
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${jwtToken}`
},
body: JSON.stringify(body)
});
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
const data = await response.json();
console.log('Response:', data);
} catch (error) {
console.error('There has been a problem with your fetch operation:', error);
}
}
sendPostRequest('JWT Token Here', 'John Smith', '123 Main', '84014', '801-555-5555');
Step 5: Retrieve Available Slots
Endpoint: https://api.heavyset.tech/api/v1/appointment/page/api/slots
Now, offer users the ability to book an appointment by fetching the available slots using the slots endpoint. Present these slots to the users for selection.
async function getTimeSlots(jwtToken) {
const url = 'https://api.heavyset.tech/api/v1/appointment/page/api/slots';
try {
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${jwtToken}`
}
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const timeSlots = await response.json();
return timeSlots;
} catch (error) {
console.error('Error fetching time slots:', error);
throw error;
}
}
// Example usage
const jwtToken = 'your-jwt-token-here'; // Replace with the actual JWT token
getTimeSlots(jwtToken)
.then(timeSlots => console.log('Time Slots:', timeSlots))
.catch(error => console.error('Error:', error));
Step 6: Book an Appointment
Endpoint: https://api.heavyset.tech/api/v1/appointment/page/api/appointment
Upon slot selection, make the final call to the appointment endpoint with the selected blockId, to book an appointment.
async function submitAppointment(jwtToken, appointmentData) {
const url = 'https://api.heavyset.tech/api/v1/appointment/page/api/appointment';
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${jwtToken}`
},
body: JSON.stringify(appointmentData)
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error('Error during the fetch operation: ', error);
throw error;
}
}
// Example usage
const appointmentData = {
blockId: 'a0p8X00000XRDoJQAX' // Replace with actual blockId
};
submitAppointment('JWT Token Here', appointmentData)
.then(data => console.log('Appointment submitted successfully:', data))
.catch(error => console.error('Error:', error));
Conclusion
The HeavySet API is a resource for HeavySet Tech customers seeking a customized user interface experience beyond the provided web form iframe application. This guide outlines the essential steps to integrate lead capturing and appointment scheduling functionalities directly into your own tailored user interfaces, offering an alternative for enhanced customization and control. For more details and options, consult the HeavySet Tech REST API Documentation .