JSON is an open standard file format, and data interchange format, that uses human-readable text to store and transmit data objects consisting of attribute-value pairs and array data types. It is a very common data format, with a diverse range of applications, such as serving as a replacement for XML in AJAX systems. The Wodify API returns in JSON.
In this article, we will cover:
- Using the formatted workout endpoint
Retrieving a Formatted workout
This endpoint can be used to retrieve information about a workout, included an html formatted version of the workout that can be displayed in a web page. To use it, refer to the example script and replace the variables at the bottom of the script with the appropriate input values for:
- your API key, retrieved from the digital presence -> Web Integrations page
- The location name corresponding to the workout from which you want to retrieve the workout
- the program name corresponding to the program that the workout belongs to
GET endpoint: https://api.wodify.com/v1/workouts/formattedworkout
Example Script:
<div id="wodcontainer"></div>
<script type="text/javascript">
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": apiKey
}
})
.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}`;
});
};
getWodDetails({
elementId: "wodcontainer",
apiKey: "YourAPIKeyGoesHere",
location: "LocationNameGoesHere",
program: "ProgramNameGoesHere"
});
</script>
JSON Sample Response:
Updated Response format (No Longer Wrapped in a record list, all else is the same):
{
"APIWod":
{
"WodHeader":
{
"Id":"17286",
"Date":"2012-11-20",
"ShouldPublish":"False",
"Name":"Lactic tuesday",
"OwnershipLevelId":"3",
"UserId":"0",
"ProgramId":"5",
"ResultsPosted":"False",
"HasBeenSaved":"False",
"CreatedBy":"17597",
"CreatedOn":"2013-04-03T14:50:36",
"UpdatedBy":"17597",
"UpdatedOn":"2013-04-03T14:50:36",
"IsActive":"True"
},
"Components":
{
"Component":
[
{
"Id":"14223",
"ComponentTypeId":"2",
"OwnershipLevelId":"3",
"PerformanceResultTypeId":"4",
"UserId":"0",
"Description":"4 rds\n60 sec amrap max cal row\n60 sec amrap Double unders\n60 sec Amrap Kb swings (53/35)\nRest/walk for 3 mins",
"IsBenchmark":"True",
"HasBeenSaved":"True",
"IsNewComponentEmailSent":"True",
"AllowRxPlus":"False",
"Rounds":"0",
"EachRoundTypeId":"0",
"CreatedBy":"17597",
"CreatedOn":"2013-04-03T14:50:38",
"UpdatedBy":"17597",
"UpdatedOn":"2013-04-03T14:50:38",
"IsActive":"True"
},
{
"Id":"14111",
"ComponentTypeId":"4",
"OwnershipLevelId":"3",
"PerformanceResultTypeId":"1",
"UserId":"0",
"Name":"Pullups (max reps)",
"Description":"B. Back rack barbell Bulgarian split squats 3 x 6 per leg \nrest 1 min btw legs\nC. Weighted plank hold accumulate 4 mins\nD. Shuttle sprints x 3 rest 2 mins\n (25m up and back, 50m up and back =1)",
"IsBenchmark":"True",
"HasBeenSaved":"True", "IsNewComponentEmailSent":"True",
"AllowRxPlus":"False",
"Rounds":"0",
"EachRoundTypeId":"0",
"CreatedBy":"17597",
"CreatedOn":"2013-04-03T14:45:07",
"UpdatedBy":"17597",
"UpdatedOn":"2013-04-03T14:45:07",
"IsActive":"True"
}
]
},
"CreatedByUser":
{
"Id":"0",
"Is_Active":"True"
},
"UpdatedByUser":
{
"Id":"0",
"Is_Active":"True"
},
"CreatedDate":"2013-04-03",
"UpdatedDate":"04/03/2013 14:50:36",
"Location":
{
"Id":"5",
"Name":"Main",
"StateId":"0",
"CountryId":"0",
"CreatedBy":"17597",
"CreatedOn":"2000-01-01",
"UpdatedBy":"0",
"IsActive":"True"
},
"Program":
{
"Id":"5",
"Name":"Crossfit",
"Description":"Crossfit",
"CreatedBy":"17597",
"CreatedOn":"2000-01-01",
"UpdatedBy":"0",
"Is_Active":"True"
},
"CoachNotes": {
"Id": "7473466",
"ObjectId": "9497205",
"ObjectTypeId": "15",
"Note": "<p>test</p>",
"CustomerId": "XX"
},
"Announcements":
{
"Announcement":
{
"Id":"17",
"Message":"Test Announcement",
"FromDate":"2012-04-02",
"ToDate":"2012-12-21",
"IsExternal":"True",
"CreatedBy":"19330",
"CreatedOn":"2013-04-05T12:11:50",
"UpdatedBy":"19330",
"UpdatedOn":"2013-04-05T12:11:50",
"IsActive":"True"
}
}
}
}
Error Responses:
If the workout you are trying to find does not exist, the response will contain an API Error field with the details. For example:
{
"APIError":
{
"ResponseCode":"400",
"ErrorMessage":"No workout found matching those criteria. Please change your search parameters and try again."
}
}
If you need any additional assistance with Retrieving Formatted Workout Endpoints, feel free to reach out to us at support@wodify.com or via Priority Live Chat in your admin account (Promote only).
Comments