/**
* @param {{inputData: InputData}}
*/
export default async function main({inputData}) {
// Construct the request body with the provided details
const requestBody = {
customer: {
first_name: inputData.firstName || '',
last_name: inputData.lastName || '',
email: inputData.email || '',
mobile_number: inputData.phoneNumber || '',
lead_source: inputData.leadSource || '',
notes: inputData.notes || '',
addresses: [
{
street: inputData.street || '',
city: inputData.city || '',
state: inputData.state || '',
zip: inputData.zip || ''
}
]
},
lead_source: inputData.leadSource || ''
};
// Make a POST request to create a lead in Housecall Pro
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer YOUR ZAPIER API'
},
body: JSON.stringify(requestBody)
});
// Check if the response is successful
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
throw new Error(`API Error: ${response.status} - ${JSON.stringify(errorData)}`);
}
// Return the response data
const responseData = await response.json();
return { result: responseData };
}