JSON example usage, sample, and response

Follow

Wodify_Bar_All.png

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 can return either JSON or XML. 

 

In this article, we will discuss:

 

Wodify REST API Endpoints

GET: https://app.wodify.com/API/WODs_v1.aspx?apikey=&location=&program=&date=&type=&encoding=

Wodify's REST API can use response types XML or JSON.


JSON Example Usage

<!doctype HTML>
<html>
<head> </head>
<body>
  <?php  
    /*            
    * Quick function that makes a call to the Api/WODs_v1 endpoint, getting WODS for a certain date.          
    * Parameters:          
    * $apikey = your api key          
    * $date = the date the wod took place, in YYYY/MM/DD format          
    * $location = the name of the location where the wod took place      
    * $program = the name of the program that the wod was a part of           * $isJSON = a boolean value indicating the response format
         
    * $encoding = "utf-8", "utf-16", or "ascii"          
    */        

    function GetWODs($apikey, $date, $location, $program, $isJSON, $encoding)
    {              
      $data = array(                
        "apikey" => $apikey,                
        "date" => $date,                
        "location" => $location,                
        "program" => $program,                
        "type" => $isJSON ? "json" : "xml",
        "encoding" => $encoding            
      );              

      $ch = curl_init();              
      $url = sprintf("%s?%s", "https://app.wodify.com/API/WODs_v1.aspx",
      http_build_query($data));              
      curl_setopt($ch, CURLOPT_URL, $url);            
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);            
      curl_setopt($ch, CURLOPT_HEADER, false);            
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');              
      $result = curl_exec($ch);            
      return $result;        
    }  
  $json = true; //JSON        
  $response = GetWODs("np3g23grc9j81jlamjqmu1yo0", "2012-11-20", "Main", "Crossfit", $json);        
  $jsonResponse = json_decode($response, true);        
  $jsonWod = $jsonResponse["RecordList"]["APIWod"]["WodHeader"];
  ?>
</body>
</html>


JSON Sample Response:

{    
  "RecordList":
    {      
      "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"            
                }          
            }      
        }    
    }
}


JSON Errors


If the workout you are trying to find does not exist, the response will contain an APIError 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 JSON, feel free to reach out to us at support@wodify.com or via Priority Live Chat in your admin account (Promote only).

Comments

Check the current status of our products

View status