var getWodDetails = ({ elementId, apiKey, location, program }) => { var today = new Date(); var date = `${today.getFullYear()}-${(today.getMonth() + 1).toString().padStart(2, '0')}-${today.getDate().toString().padStart(2, '0')}`; var fetchUrl = `https://api.wodify.com/v1/workouts/formattedworkout?date=${date}&location=${encodeURIComponent(location)}&program=${encodeURIComponent(program)}`; fetch(fetchUrl, { headers: { "x-api-key": SY52plygg53ihOgpLuHVHaxpOcyF4J8I4ZwVLvJT } }) .then(response => { if (!response.ok) { return response.json().then(errorData => { if (errorData.MoreInfo) { throw new Error(errorData.MoreInfo); } else { throw new Error('An unknown error occurred.'); } }); } return response.json(); }) .then(data => { var container = document.getElementById(elementId); if (data && data.APIWod && data.APIWod.FormattedWOD) { container.innerHTML = data.APIWod.FormattedWOD; } else { container.innerHTML = 'No workout data found.'; } }) .catch(error => { console.error('There was a problem with the fetch operation:', error); var container = document.getElementById(elementId); container.innerHTML = `Error: ${error.message}`; }); };