### GET /websites/myfitnesspalapi/user Source: https://myfitnesspalapi.com/docs/example-response-with-fields-parameter Retrieves the user's profile information, including account details, location, and goal preferences. ```APIDOC ## GET /websites/myfitnesspalapi/user ### Description Retrieves the user's profile information, including account details, location, and goal preferences. ### Method GET ### Endpoint /websites/myfitnesspalapi/user ### Parameters #### Query Parameters * **fields** (string) - Optional - Comma-separated list of fields to include in the response. Example: `profiles,account,location_preferences,goal_preferences,diary_preferences` ### Request Example ``` GET /websites/myfitnesspalapi/user?fields=profiles,account,location_preferences,goal_preferences,diary_preferences ``` ### Response #### Success Response (200) - **item** (object) - Contains the user's data. - **id** (string) - The user's unique identifier. - **username** (string) - The user's username. - **profiles** (array) - An array of profile objects. - **type** (string) - The type of profile (e.g., "user"). - **birthdate** (string) - The user's birthdate in YYYY-MM-DD format. - **sex** (string) - The user's sex (e.g., "M", "F"). - **activity_factor** (string) - The user's activity factor (e.g., "active"). - **height** (object) - The user's height. - **value** (number) - The height value. - **unit** (string) - The unit of height (e.g., "inches", "cm"). - **headline** (string) - A short user headline. - **account** (object) - Account-related information. - **created_at** (string) - The date and time the account was created in ISO 8601 format. - **location_preferences** (object) - User's location preferences. - **time_zone** (string) - The user's time zone. - **goal_preferences** (object) - User's goal preferences. - **daily_step_goal** (integer) - The daily step goal. - **daily_energy_goal** (object) - The daily energy goal. - **value** (number) - The energy goal value. - **unit** (string) - The unit of energy (e.g., "calories"). - **diary_preferences** (object) - User's diary preferences. - **meal_names** (array) - An array of meal names. #### Response Example ```json { "item": { "id": "fs34o4ifseijo4n9", "username": "an_mfp_username", "profiles": [ { "type": "user", "birthdate": "1980-12-28", "sex": "M", "activity_factor": "active", "height": { "value": 70, "unit": "inches" }, "headline": "The arrival of winter is imminent" } ], "account": { "created_at": "2008-06-01T13:45:04Z" }, "location_preferences": { "time_zone": "America/Los_Angeles" }, "goal_preferences": { "daily_step_goal": 15000, "daily_energy_goal": { "value": 2100, "unit": "calories" } }, "diary_preferences": { "meal_names": ["Breakfast", "Lunch", "Dinner", "Snacks"] } } } ``` ``` -------------------------------- ### MyFitnessPal API Pagination Link Header Example Source: https://myfitnesspalapi.com/docs/collection-requests An example of an HTTP `Link` header returned by the MyFitnessPal API for paginated collections. This header guides clients on how to fetch the next or previous pages of resources using pagination tokens and the `max_items` parameter. ```http Link: ; rel=next, ; rel=previous ``` -------------------------------- ### Create Measurement Request Body Example (JSON) Source: https://myfitnesspalapi.com/docs/measurements-post Example of a JSON request body for creating multiple measurement entries, such as weight, with specified units and dates. The 'type', 'value', 'unit', and 'date' fields are mandatory for each measurement item. ```json { "items": [ { "type": "weight", "value": 208, "unit": "pounds", "date": "2014-04-16" }, { "type": "weight", "value": 203, "unit": "pounds", "date": "2014-05-06" }, { "type": "weight", "value": 200, "unit": "pounds", "date": "2014-06-20" } ] } ``` -------------------------------- ### GET /v2/diary Source: https://myfitnesspalapi.com/docs/appendix-full-request-examples Retrieves diary entries for a specified date, including meal and exercise types. This endpoint supports filtering by entry type and requesting specific fields like nutritional content and exercise details. ```APIDOC ## GET /v2/diary ### Description Retrieves diary entries for a specified date, including meal and exercise types. Supports filtering by entry type and requesting specific fields. ### Method GET ### Endpoint https://api.myfitnesspal.com/v2/diary ### Parameters #### Path Parameters None #### Query Parameters - **entry_date** (string) - Required - The date for which to retrieve diary entries (YYYY-MM-DD). - **types** (string) - Optional - A comma-separated list of diary entry types to retrieve (e.g., "diary_meal,exercise"). - **fields[]** (string) - Optional - An array of fields to include in the response (e.g., "nutritional_contents", "exercise", "energy"). ### Request Example ``` GET https://api.myfitnesspal.com/v2/diary?entry_date=2014-08-25&types=diary_meal,exercise&fields[]=nutritional_contents&fields[]=exercise&fields[]=energy HTTP/1.1 Host: api.myfitnesspal.com Accept: application/json Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 mfp-client-id: awesome_fitness_tracker mfp-user-id: 2320694511409 Authorization: Bearer f4e5ab42081e485949ed3ea35cf3857s0ebd0a62 ``` ### Response #### Success Response (200) - **items** (array) - An array of diary entries. - **type** (string) - The type of diary entry (e.g., "diary_meal", "exercise"). - **date** (string) - The date of the diary entry. - **diary_meal** (string) - The name of the meal (if type is "diary_meal"). - **nutritional_contents** (object) - Nutritional breakdown of the meal (if requested). - **protein** (number) - Protein in grams. - **fat** (number) - Fat in grams. - **saturated_fat** (number) - Saturated fat in grams. - **polyunsaturated_fat** (number) - Polyunsaturated fat in grams. - **monounsaturated_fat** (number) - Monounsaturated fat in grams. - **trans_fat** (number) - Trans fat in grams. - **cholesterol** (number) - Cholesterol in milligrams. - **sodium** (number) - Sodium in milligrams. - **potassium** (number) - Potassium in milligrams. - **fiber** (number) - Fiber in grams. - **sugar** (number) - Sugar in grams. - **vitamin_a** (number) - Vitamin A percentage of daily value. - **vitamin_c** (number) - Vitamin C percentage of daily value. - **calcium** (number) - Calcium percentage of daily value. - **iron** (number) - Iron percentage of daily value. - **carbohydrates** (number) - Carbohydrates in grams. - **energy** (object) - Energy information. - **unit** (string) - Unit of energy (e.g., "calories"). - **value** (integer) - Value of energy. - **id** (string) - The unique identifier of the exercise entry. - **exercise** (object) - Details about the exercise (if type is "exercise" and requested). - **id** (integer) - The unique identifier of the exercise. - **duration** (integer) - The duration of the exercise in seconds (if type is "exercise"). - **energy** (object) - Energy information for the exercise (if type is "exercise" and requested). - **unit** (string) - Unit of energy. - **value** (integer) - Value of energy. - **start_time** (string) - The start time of the exercise in ISO 8601 format (if type is "exercise"). - **avg_heart_rate** (null) - Average heart rate (if applicable). - **max_heart_rate** (null) - Maximum heart rate (if applicable). - **distance** (null) - Distance covered (if applicable). - **max_speed** (null) - Maximum speed (if applicable). - **elevation_change** (null) - Elevation change (if applicable). #### Response Example ```json { "items": [ { "type":"diary_meal", "date":"2014-08-25", "diary_meal":"Breakfast", "nutritional_contents": { "protein": 22.35, "fat": 25.72, "saturated_fat": 5.5, "polyunsaturated_fat": 9.08, "monounsaturated_fat": 8.79, "trans_fat": 0.0, "cholesterol": 420.44, "sodium": 945.06, "potassium": 454.4, "fiber": 9.01, "sugar": 26.26, "vitamin_a": 14.93, "vitamin_c": 10.58, "calcium": 10.31, "iron": 25.35, "carbohydrates": 49.72, "energy": { "unit": "calories", "value": 515 } } }, { "type":"diary_meal", "date": "2014-08-25", "diary_meal": "Lunch", "nutritional_contents": { "protein": 30.71, "fat": 4.27, "saturated_fat": 1.5, "polyunsaturated_fat": 0.8, "monounsaturated_fat": 1.33, "trans_fat": 0.0, "cholesterol": 77.3, "sodium": 747.84, "potassium": 841.76, "fiber": 3.15, "sugar": 59.17, "vitamin_a": 1.1, "vitamin_c": 21.7, "calcium": 5.91, "iron": 8.12, "carbohydrates": 92.81, "energy": { "unit": "calories", "value": 526 } } }, { "id": "61a4452be5b1db6813cdc85546f5c49eea7585bc", "type": "exercise", "date": "2014-08-25", "exercise": { "id": 134026223316461 }, "duration": 1800, "energy": { "unit": "calories", "value": 210 }, "start_time": "2014-08-25T22: 00: 00Z", "avg_heart_rate": null, "max_heart_rate": null, "distance": null, "max_speed": null, "elevation_change": null } ] } ``` ``` -------------------------------- ### GET /measurements Source: https://myfitnesspalapi.com/docs/appendix-migrate-get_weight Retrieves a specific weight measurement for a given date. This is achieved by making a GET request to the /measurements endpoint with the type set to 'weight' and the entry_date set to the desired date. ```APIDOC ## GET /measurements ### Description Retrieves a specific weight measurement for a given date. This is achieved by making a GET request to the /measurements endpoint with the type set to 'weight' and the entry_date set to the desired date. ### Method GET ### Endpoint /measurements ### Parameters #### Query Parameters - **type** (string) - Required - Must be set to "weight". - **entry_date** (string) - Required - The desired date for which to retrieve the weight measurement (e.g., "YYYY-MM-DD"). ### Request Example This endpoint does not have a request body. ### Response #### Success Response (200) - **measurement_id** (integer) - The unique identifier for the weight measurement. - **type** (string) - The type of measurement, which will be "weight". - **value** (float) - The weight measurement value. - **unit** (string) - The unit of the weight measurement (e.g., "lbs", "kg"). - **entry_date** (string) - The date the measurement was recorded (e.g., "YYYY-MM-DD"). #### Response Example { "measurement_id": 12345, "type": "weight", "value": 155.5, "unit": "lbs", "entry_date": "2023-10-27" } ``` -------------------------------- ### Example Request Body - Update Daily Step Goal (JSON) Source: https://myfitnesspalapi.com/docs/patch-request-example An example JSON request body for updating a user's daily step goal. This demonstrates how to specify nested properties like 'goal_preferences' and 'daily_step_goal'. Only the specified properties within the request body will be modified. ```json { "item": { "goal_preferences": { "daily_step_goal": 12000 } } } ``` -------------------------------- ### Standard Responses - GET Source: https://myfitnesspalapi.com/docs/standard-responses Describes the standard successful response for GET requests. ```APIDOC ## GET Standard Response ### Description Successful GET requests will return a 200 OK status code along with representations of the requested resource(s). ### Method GET ### Endpoint [Specific endpoint for the GET request] ### Parameters #### Path Parameters None specified. #### Query Parameters None specified. #### Request Body None applicable. ### Request Example None applicable. ### Response #### Success Response (200) - **resource** (object/array) - Representation of the requested resource(s). #### Response Example ```json { "example": "representation of the requested resource(s)" } ``` ``` -------------------------------- ### MyFitnessPal API Collection Request Example (GET /diary) Source: https://myfitnesspalapi.com/docs/collection-requests Example of a GET request to the MyFitnessPal API to retrieve a paginated collection of diary entries. It specifies the maximum number of items to return (`max_items`) and requests specific fields. The response includes a `Link` header for pagination. ```http GET /diary?type=diary_meal&date=2014-07-15&max_items=2&fields[]=nutritional_contents Response header: Link: ; rel=next Response body: { "items": [ { "type": "diary_meal", "date": "2014-07-15", "diary_meal": "Breakfast", "nutritional_contents": { "energy": { "unit": "calories", "value": 350 }, "fat": 6.8, "protein": 19, "sugar": 8 } }, { "type": "diary_meal", "date": "2014-07-15", "diary_meal": "Lunch", "nutritional_contents": { "energy": { "unit": "calories", "value": 531 }, "fat": 12, "protein": 25, "sugar": 9, "cholesterol": 125, "fiber": 6, "vitamin_a": 35, "vitamin_c": 40 } } ] } ``` -------------------------------- ### Example MyFitnessPal API Response (JSON) Source: https://myfitnesspalapi.com/docs/example-response-with-fields-parameter This JSON object represents a typical response from the MyFitnessPal API. It includes detailed user information such as profiles, account creation date, location preferences, goal settings, and diary meal names. This structure is useful for understanding the data returned by the API for user-specific information. ```json { "item": { "id": "fs34o4ifseijo4n9", "username": "an_mfp_username", "profiles": [ { "type": "user", "birthdate": "1980-12-28", "sex": "M", "activity_factor": "active", "height": { "value": 70, "unit": "inches" }, "headline": "The arrival of winter is imminent" } ], "account": { "created_at": "2008-06-01T13:45:04Z" }, "location_preferences": { "time_zone": "America/Los_Angeles" }, "goal_preferences": { "daily_step_goal": 15000, "daily_energy_goal": { "value": 2100, "unit": "calories" } }, "diary_preferences": { "meal_names": ["Breakfast", "Lunch", "Dinner", "Snacks"] } } } ``` -------------------------------- ### GET /exercises/:exerciseId Source: https://myfitnesspalapi.com/docs/exercises-diary-get Retrieves a specific exercise by its ID. It fetches from the public database and also considers user-specific private exercises if a user ID is provided. ```APIDOC ## GET /exercises/:exerciseId ### Description Retrieves the exercise with the given identifier from the public database and, if the **m​fp-user-id** header contains a valid user id, the user’s private exercises. ### Method GET ### Endpoint `/exercises/:exerciseId` ### Parameters #### Path Parameters - **exerciseId** (string) - Required - The unique identifier for the exercise. #### Query Parameters - **version** (string) - Optional - The version of the exercise being requested. If none is present, the current version is returned. Default: `abc123qwerty` #### Request Body None ### Request Example None ### Response #### Success Response (200) - **item** (object) - Contains the exercise details. - **id** (string) - The unique identifier of the exercise. - **version** (string) - The version of the exercise. - **type** (string) - The type of exercise (e.g., cardio). - **description** (string) - A description of the exercise. - **mets** (number) - The MET (Metabolic Equivalent of Task) value for the exercise. - **public** (boolean) - Indicates if the exercise is public. #### Response Example ```json { "item": { "id": "zXKDV84eqnio8a4n", "version": "d980v43", "type": "cardio", "description": "Curling", "mets": 4, "public": true } } ``` ### Required Permission Scope `private-exercises` ``` -------------------------------- ### POST /v2/diary Source: https://myfitnesspalapi.com/docs/appendix-full-request-examples Creates a new diary entry, specifically an exercise entry, within the MyFitnessPal application. This endpoint allows users to log activities with details such as duration and caloric expenditure. ```APIDOC ## POST /v2/diary ### Description This request creates a Diary entry of type **exercise**. ### Method POST ### Endpoint https://api.myfitnesspal.com/v2/diary ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **items** (array) - Required - An array containing diary item objects. - **type** (string) - Required - The type of diary entry (e.g., "exercise"). - **date** (string) - Required - The date of the diary entry in YYYY-MM-DD format. - **exercise** (object) - Required - Details about the exercise. - **id** (string) - Required - The unique identifier of the exercise. - **start_time** (string) - Required - The start time of the exercise in ISO 8601 format. - **duration** (integer) - Required - The duration of the exercise in seconds. - **energy** (object) - Required - Energy information for the exercise. - **unit** (string) - Required - The unit of energy (e.g., "calories"). - **value** (integer) - Required - The value of energy. ### Request Example ```json { "items": [ { "type": "exercise", "date": "2014-08-25", "exercise": { "id": "134026223316461" }, "start_time": "2014-08-25T15:00:00-07:00", "duration": 1800, "energy": { "unit": "calories", "value": 210 } } ] } ``` ### Response #### Success Response (200) - **items** (array) - An array containing the created diary entry. - **id** (string) - The unique identifier of the created diary entry. - **type** (string) - The type of diary entry. - **date** (string) - The date of the diary entry. - **exercise** (object) - Details about the exercise. - **id** (string) - The unique identifier of the exercise. - **duration** (integer) - The duration of the exercise in seconds. - **energy** (object) - Energy information for the exercise. - **unit** (string) - The unit of energy. - **value** (integer) - The value of energy. - **start_time** (string) - The start time of the exercise in ISO 8601 format. - **avg_heart_rate** (null) - Average heart rate (if applicable). - **max_heart_rate** (null) - Maximum heart rate (if applicable). - **distance** (null) - Distance covered (if applicable). - **max_speed** (null) - Maximum speed (if applicable). - **elevation_change** (null) - Elevation change (if applicable). #### Response Example ```json { "items": [ { "id": "61a4152be5b1de6813ceea5546f5c099aea751b9c", "type": "exercise", "date": "2014-08-25", "exercise": { "id": "134026223316461" }, "duration": 1800, "energy": { "unit": "calories", "value": 210 }, "start_time": "2014-08-25T22:00:00Z", "avg_heart_rate": null, "max_heart_rate": null, "distance": null, "max_speed": null, "elevation_change": null } ] } ``` ``` -------------------------------- ### Example Water Entry Response Source: https://myfitnesspalapi.com/docs/diary-get An example JSON response body for a water diary entry, indicating the date and the amount of water consumed in both cups and milliliters. ```JSON { "date":"2023-09-11", "cups":0, "milliliters":12.0 } ``` -------------------------------- ### Example Exercise and Meal Diary Entry Response Source: https://myfitnesspalapi.com/docs/diary-get An example JSON response body for diary entries, showcasing both exercise and diary meal types with their respective nutritional information and details. ```JSON { "items": [ { "type": "exercise", "id": "vcxo4nb95nt", "date": "2014-05-06", "tags": ["cardio", "outdoors"], "start_time": "2014-05-06T07:05:00-07:00", "duration": 1800, "energy": { "unit": "calories", "value": 500 }, "exercise": { "id": "b95n9898878f4", "version": "jf4o9znf4l9rjg", "type": "cardio", "description": "Running, 6.5mph", "mets": 4, "public": true } }, { "type": "diary_meal", "date": "2014-05-06", "diary_meal": "Breakfast", "nutritional_contents": { "energy": { "unit": "calories", "value": 350 }, "fat": 6.8, "protein": 19, "sugar": 8 } }, { "type": "diary_meal", "date": "2014-05-06", "diary_meal": "Lunch", "nutritional_contents": { "energy": { "unit": "calories", "value": 531 }, "fat": 12, "protein": 25, "sugar": 9, "cholesterol": 125, "fiber": 6, "vitamin_a": 35, "vitamin_c": 40 } } ] } ``` -------------------------------- ### GET /diary Source: https://myfitnesspalapi.com/docs/appendix-migrate-get_food_summary Retrieves the diary meals for a specific day. Requires 'type' to be 'diary_meal' and 'entry_date' for the desired date. ```APIDOC ## GET /diary ### Description Retrieving the diary meals for a day can be achieved with a GET request to `/diary` with a **type** of **diary_meal** and an **entry_date** of the desired date. ### Method GET ### Endpoint /diary ### Parameters #### Query Parameters - **type** (string) - Required - Must be 'diary_meal'. - **entry_date** (string) - Required - The desired date in YYYY-MM-DD format. ### Request Example ``` GET /diary?type=diary_meal&entry_date=2023-10-27 ``` ### Response #### Success Response (200) - **meals** (array) - A list of diary meals for the specified date. - **meal_name** (string) - The name of the meal. - **food_items** (array) - A list of food items within the meal. - **food_name** (string) - The name of the food item. - **serving_size** (string) - The serving size of the food item. - **quantity** (number) - The quantity of the food item. - **calories** (number) - The calories for the food item. #### Response Example ```json { "meals": [ { "meal_name": "Breakfast", "food_items": [ { "food_name": "Oatmeal", "serving_size": "1 cup", "quantity": 1, "calories": 300 } ] } ] } ``` ``` -------------------------------- ### Fetch User Info Source: https://myfitnesspalapi.com/docs/appendix-migrate-fetch_user_info Retrieve user information by making a GET request to the /users/:userId endpoint. You can specify which information to fetch using the 'fields' query parameter. ```APIDOC ## GET /users/:userId ### Description Retrieves specific user information based on the provided user ID and the requested fields. ### Method GET ### Endpoint `/users/:userId` ### Parameters #### Query Parameters - **fields** (string) - Required - Comma-separated list of fields to retrieve. Supported values include: `profiles`, `account`, `location_preferences`, `goal_preferences`, `privacy_preferences`, `diary_preferences`. ### Request Example ``` GET /users/12345?fields=profiles,account ``` ### Response #### Success Response (200) - **user_info** (object) - Contains the requested user information based on the specified fields. #### Response Example ```json { "user_info": { "profiles": { "username": "john_doe", "email": "john.doe@example.com" }, "account": { "account_id": "acc_abc123", "creation_date": "2023-01-15T10:00:00Z" } } } ``` ``` -------------------------------- ### Example API Response Body (JSON) Source: https://myfitnesspalapi.com/docs/appendix-tracking-determining-daily-totals A sample JSON response from the MyFitnessPal API for a daily diary entry request. It includes details for 'diary_meal', 'exercise', and 'steps_aggregate' entries, with nutritional content and energy values. ```json { "items": [ { "type": "diary_meal", "date": "2014-09-01", "diary_meal": "Breakfast", "nutritional_contents": { "energy": { "unit": "calories", "value": 350 }, "fat": 6.8, "carbohydrates": 38, "protein": 19, "sugar": 8 } }, { "type": "diary_meal", "date": "2014-09-01", "diary_meal": "Lunch", "nutritional_contents": { "energy": { "unit": "calories", "value": 531 }, "fat": 12, "carbohydrates": 75, "protein": 25, "sugar": 9, "cholesterol": 125, "fiber": 6, "vitamin_a": 35, "vitamin_c": 40 } }, { "type": "exercise", "id": "vcxo4nb95ntfso84nEVIVUDn3f8ndf", "date": "2014-09-01", "start_time": "2014-09-01T12:05:00Z", "duration": 1800, "energy": { "unit": "calories", "value": 500 }, "exercise": { "id": "909837568192837594", "type": "cardio", "description": "Running, 6.5mph", "mets": 4, "public": true } }, { "type": "steps_aggregate", "id": "c84bcfc2bf301397e0e2486b2d2f94fc1b313b67", "date": "2014-09-01", "steps": 12312, "energy": { "unit": "calories", "value": 1535 }, "primary": true } ] } ``` -------------------------------- ### GET /diary - Cardio Exercises Source: https://myfitnesspalapi.com/docs/appendix-migrate-get_cardio_exercises Retrieve cardio exercise entries for a specific day. This endpoint requires specifying 'exercise' as the type and providing the desired date. ```APIDOC ## GET /diary ### Description Retrieving the cardio exercise entries for a day can be achieved with a GET request to /diary with a type of exercise and an entry_date of the desired date. ### Method GET ### Endpoint /diary ### Parameters #### Query Parameters - **type** (string) - Required - Must be 'exercise'. - **entry_date** (string) - Required - The desired date for retrieving exercises (e.g., YYYY-MM-DD). ### Request Example ``` GET /diary?type=exercise&entry_date=2023-10-27 ``` ### Response #### Success Response (200) - **exercises** (array) - A list of cardio exercise objects. - **name** (string) - The name of the exercise. - **calories** (number) - The number of calories burned. - **duration** (string) - The duration of the exercise (e.g., "30 minutes"). #### Response Example ```json { "exercises": [ { "name": "Running", "calories": 350, "duration": "45 minutes" }, { "name": "Cycling", "calories": 280, "duration": "30 minutes" } ] } ``` ``` -------------------------------- ### Create Water Entry (JSON) Source: https://myfitnesspalapi.com/docs/diary-post This example shows the JSON structure for creating a single water diary entry. It requires 'date', 'units', and 'value' to log water consumption. Successful requests will return a Location header and details of the created entry. ```json { "date": "2023-09-10", "units": "milliliters", "value": 12 } ``` -------------------------------- ### POST /steps Source: https://myfitnesspalapi.com/docs/diary-post Creates multiple steps entries for a user. Each item in the request body should represent a steps entry with details like date, steps count, start time, duration, and energy. ```APIDOC ## POST /steps ### Description Creates multiple steps entries for a user. ### Method POST ### Endpoint /steps ### Request Body - **items** (array) - Required - A list of steps items to create. - **type** (string) - Required - Must be 'steps'. - **date** (string) - Required - The date of the steps entry in 'YYYY-MM-DD' format. - **steps** (integer) - Required - The number of steps recorded. - **start_time** (string) - Required - The start time of the steps entry in ISO 8601 format (e.g., '2014-07-15T00:00:00+03:00'). - **duration** (integer) - Required - The duration of the steps entry in seconds. - **energy** (object) - Optional - Energy expenditure details. - **unit** (string) - Required - The unit of energy (e.g., 'calories', 'kilojoules'). - **value** (number) - Required - The value of energy expenditure. ### Request Example ```json { "items": [ { "type": "steps", "date": "2014-07-15", "steps": 580, "start_time": "2014-07-15T00:00:00+03:00", "duration": 300, "energy": { "unit": "kilojoules", "value": 121 } }, { "type": "steps", "date": "2014-07-15", "steps": 589, "start_time": "2014-07-15T00:05:00+03:00", "duration": 300, "energy": { "unit": "kilojoules", "value": 126 } } ] } ``` ### Response #### Success Response (201 Created) - **Location** (header) - URI of the first entry created. - **body** (array) - A list of all new diary entries created. #### Response Example (Response body will contain created diary entries similar to GET request results) ``` -------------------------------- ### POST /measurements (Log Weight) Source: https://myfitnesspalapi.com/docs/appendix-migrate-log_weight Logs a weight entry for the user. This action is equivalent to creating a measurement with the type 'weight'. ```APIDOC ## POST /measurements ### Description Logs a weight entry for the user. This action is equivalent to creating a measurement with the type 'weight'. ### Method POST ### Endpoint /measurements ### Parameters #### Query Parameters - **type** (string) - Required - Specifies the type of measurement, must be 'weight'. #### Request Body - **value** (number) - Required - The recorded weight value. - **unit** (string) - Required - The unit of the weight (e.g., 'lbs', 'kg'). - **date** (string) - Optional - The date the weight was recorded (YYYY-MM-DD). ### Request Example ```json { "value": 150.5, "unit": "lbs", "date": "2023-10-27" } ``` ### Response #### Success Response (201 Created) - **id** (string) - The unique identifier for the created measurement. - **type** (string) - The type of measurement ('weight'). - **value** (number) - The recorded weight value. - **unit** (string) - The unit of the weight. - **date** (string) - The date the weight was recorded. #### Response Example ```json { "id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "type": "weight", "value": 150.5, "unit": "lbs", "date": "2023-10-27" } ``` ``` -------------------------------- ### Supported HTTP Methods Source: https://myfitnesspalapi.com/docs/about Details on the supported HTTP methods and their usage within this API. ```APIDOC ## Supported HTTP Methods This API utilizes the following standard HTTP methods for resource manipulation: ### GET Used for the retrieval of resources. ### POST Used for the creation of new resources. ### DELETE Used for the deletion of resources. ### PATCH Used for updating resources. The PATCH method requests that a set of changes described in the request entity be applied to the resource identified by the Request-URI. **PATCH Request Body Specification:** A "set of changes" is defined as the properties present in the request body of a resource representation. Performing a PATCH operation updates only the properties included in the request body. Properties not included in the body will not be changed, except for automatic properties like `last-updated-time`. ``` -------------------------------- ### Request Daily Totals (API) Source: https://myfitnesspalapi.com/docs/appendix-tracking-determining-daily-totals Example of a GET request to the MyFitnessPal API to retrieve daily diary entries, including energy intake from food and energy expenditure from exercise and steps. This is useful for calculating a user's total daily energy balance. ```http GET /v2/diary?entry_date=2014-09-01 &fields[]=energy &fields[]=nutritional_contents &fields[]=exercise ``` -------------------------------- ### Authorization Response Source: https://myfitnesspalapi.com/docs/auth-response Details the query parameters appended to the redirect_uri upon successful user authorization. ```APIDOC ## GET /websites/myfitnesspalapi ### Description Upon successful user authorization, the API redirects the user to the specified `redirect_uri` and appends query parameters containing an authorization code and the original state value if provided. ### Method GET ### Endpoint /websites/myfitnesspalapi ### Query Parameters - **redirect_uri** (string) - Required - The URI to redirect the user to after authorization. - **state** (string) - Optional - The value provided by the client to maintain state between the request and callback. ### Response #### Success Response (302 Found) This endpoint results in a redirect. The `Location` header will contain the `redirect_uri` with the following query parameters: - **code** (string) - Required - The authorization code. This code is approximately forty (40) characters long and expires after ten (10) minutes. It can only be used once. - **state** (string) - Optional - If the original request included a `state` parameter, this will contain the same value. Otherwise, this parameter will not be appended. ### Response Example ``` Location: https://myapp.com/callback?code=SplxlOBeZQQYbYS6WxSbIA&state=xyz ``` ``` -------------------------------- ### GET Diary Entries - MyFitnessPal API Source: https://myfitnesspalapi.com/docs/appendix-full-request-examples This snippet shows how to retrieve diary entries, including nutritional content and exercise details, from the MyFitnessPal API. It utilizes query parameters to filter entries by date and type, and to specify desired fields. The response is a JSON object containing an array of diary items, each with its respective details. ```HTTP GET https://api.myfitnesspal.com/v2/diary ?entry_date=2014-08-25 &types=diary_meal,exercise &fields[]=nutritional_contents &fields[]=exercise &fields[]=energy HTTP/1.1 Host: api.myfitnesspal.com Accept: application/json Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 mfp-client-id: awesome_fitness_tracker mfp-user-id: 2320694511409 Authorization: Bearer f4e5ab42081e485949ed3ea35cf3857s0ebd0a62 ``` Response: ``` Content-Type: application/json; charset=utf-8 Cache-Control: max-age=0, private, must-revalidate Connection: close { "items": [ { "type":"diary_meal", "date":"2014-08-25", "diary_meal":"Breakfast", "nutritional_contents": { "protein": 22.35, "fat": 25.72, "saturated_fat": 5.5, "polyunsaturated_fat": 9.08, "monounsaturated_fat": 8.79, "trans_fat": 0.0, "cholesterol": 420.44, "sodium": 945.06, "potassium": 454.4, "fiber": 9.01, "sugar": 26.26, "vitamin_a": 14.93, "vitamin_c": 10.58, "calcium": 10.31, "iron": 25.35, "carbohydrates": 49.72, "energy": { "unit": "calories", "value": 515 } } }, { "type":"diary_meal", "date": "2014-08-25", "diary_meal": "Lunch", "nutritional_contents": { "protein": 30.71, "fat": 4.27, "saturated_fat": 1.5, "polyunsaturated_fat": 0.8, "monounsaturated_fat": 1.33, "trans_fat": 0.0, "cholesterol": 77.3, "sodium": 747.84, "potassium": 841.76, "fiber": 3.15, "sugar": 59.17, "vitamin_a": 1.1, "vitamin_c": 21.7, "calcium": 5.91, "iron": 8.12, "carbohydrates": 92.81, "energy": { "unit": "calories", "value": 526 } } }, { "id": "61a4452be5b1db6813cdc85546f5c49eea7585bc", "type": "exercise", "date": "2014-08-25", "exercise": { "id": 134026223316461 }, "duration": 1800, "energy": { "unit": "calories", "value": 210 }, "start_time": "2014-08-25T22: 00: 00Z", "avg_heart_rate": null, "max_heart_rate": null, "distance": null, "max_speed": null, "elevation_change": null } ] } ``` ``` -------------------------------- ### GET Request without 'fields' parameter - MyFitnessPal API Source: https://myfitnesspalapi.com/docs/get-request-query-param Illustrates a GET request to the MyFitnessPal API without the 'fields' query parameter. This results in a default response containing essential properties of the requested resource. No specific dependencies are required to execute this basic API call. ```http GET /diary/9348fwn4go89v48ghg ``` ```json { "item": { "id": "9348fwn4go89v48ghg", "type": "exercise", "date": "2014-07-15", "start_time": "2014-07-15T08:30:05-07:00", "duration": 2700 } } ```