//native
/**
* Post nutrition logs to a provider
* Used to post nutrition logs to a provider. This endpoint only works for users connected via Fitbit. Returns error for other providers.
*/
export async function main(auth: RT.Terra, body: Body) {
const url = new URL(`https://api.tryterra.co/v2/nutrition`)
const response = await fetch(url, {
method: 'POST',
headers: {
'dev-id': auth.devId,
'Content-Type': 'application/json',
'X-api-key': auth.apiKey
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/
/**
* Enum representing the category the consumed food/meal falls under (i.e. Breakfast/Lunch/Dinner etc).
*/
export type HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasMealTypeYaml =
| Unknown
| Breakfast
| MorningSnack
| Lunch
| AfternoonSnack
| Dinner
| Snack
/**
* Meal type is unknown or could not be determined.
*/
export type Unknown = 0
/**
* Meal consumed in the morning, typically the first meal of the day.
*/
export type Breakfast = 1
/**
* Light meal or snack consumed in the morning, between breakfast and lunch.
*/
export type MorningSnack = 2
/**
* Meal consumed around midday, typically the second meal of the day.
*/
export type Lunch = 3
/**
* Light meal or snack consumed in the afternoon, between lunch and dinner.
*/
export type AfternoonSnack = 4
/**
* Meal consumed in the evening, typically the last main meal of the day.
*/
export type Dinner = 5
/**
* Any light meal or snack consumed at any time, not fitting into main meal categories.
*/
export type Snack = 6
/**
* Represents units used for nutrition measurements
*/
export type HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionUnitsYaml =
| Unknown1
| Gram
| Teaspoon
| Tablespoon
| Cup
| MediumEgg
| LargeEgg
| SmallEgg
| Milliliter
| Ounce
| Count
| Scoop
| FluidOunce
/**
* The unit of measurement is unknown or not specified.
*/
export type Unknown1 = 0
/**
* Measurement in grams, a metric unit of mass.
*/
export type Gram = 1
/**
* Measurement in teaspoons, approximately 5 milliliters.
*/
export type Teaspoon = 2
/**
* Measurement in tablespoons, approximately 15 milliliters.
*/
export type Tablespoon = 3
/**
* Measurement in cups, approximately 240 milliliters.
*/
export type Cup = 4
/**
* Quantity measured in medium-sized eggs.
*/
export type MediumEgg = 5
/**
* Quantity measured in large-sized eggs.
*/
export type LargeEgg = 6
/**
* Quantity measured in small-sized eggs.
*/
export type SmallEgg = 7
/**
* Measurement in milliliters, a metric unit of volume.
*/
export type Milliliter = 8
/**
* Measurement in ounces, approximately 28 grams.
*/
export type Ounce = 9
/**
* Quantity measured by individual count or number of items.
*/
export type Count = 10
/**
* Quantity measured in scoops, typically used for protein powder or supplements.
*/
export type Scoop = 11
/**
* Measurement in fluid ounces, approximately 30 milliliters.
*/
export type FluidOunce = 12
/**
* Indicates whether the timestamps in this payload are localized (LOCAL) or in UTC.
*/
export type HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasTimestampLocalizationYaml =
0 | 1
export interface Body {
/**
* Nutrition entry to post to data provider
*/
data: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionYaml[]
[k: string]: unknown
}
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionYaml {
/**
* Information on drinks the user consumed throughout the day.
*/
drink_samples?: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasDrinkSampleYaml[]
/**
* Information on individual foods consumed throughout a given day.
*/
meals?: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasMealYaml[]
metadata: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMetadataYaml
summary?: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionSummaryYaml
[k: string]: unknown
}
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasDrinkSampleYaml {
/**
* Time with which the record is associated, in ISO8601 format with microsecond precision. TimeZone info will be provided whenever possible. If absent, the time corresponds to the user's local time
*/
timestamp?: string
/**
* Volume of drink consumed
*/
drink_volume?: number
/**
* Unit of measurement for the drink
*/
drink_unit?: string
/**
* Name of drink consumed.
*/
drink_name?: string
[k: string]: unknown
}
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasMealYaml {
micros: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMicrosYaml
type: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasMealTypeYaml
/**
* Identifier for food logged by the user.
*/
id: string
/**
* Timestamp the food is associated with, in ISO8601 format, with microsecond precision.
*/
timestamp: string
quantity: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionQuantityYaml
/**
* Name of food logged by the user.
*/
name: string
macros: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMacrosYaml
[k: string]: unknown
}
/**
* Micronutrient information for associated food.
*/
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMicrosYaml {
/**
* Biotin content of the associated food(s).
*/
biotin_mg?: number
/**
* Caffeine content of the associated food(s).
*/
caffeine_mg?: number
/**
* Calcium content of the associated food(s).
*/
calcium_mg?: number
/**
* Chloride content of the associated food(s).
*/
chloride_mg?: number
/**
* Chromium content of the associated food(s).
*/
chromium_mg?: number
/**
* Copper content of the associated food(s).
*/
copper_mg?: number
/**
* Folate content of the associated food(s).
*/
folate_mg?: number
/**
* Folic Acid content of the associated food(s).
*/
folic_acid_mg?: number
/**
* Iodine content of the associated food(s).
*/
iodine_mg?: number
/**
* Iron content of the associated food(s).
*/
iron_mg?: number
/**
* Magnesium content of the associated food(s).
*/
magnesium_mg?: number
/**
* Manganese content of the associated food(s).
*/
manganese_mg?: number
/**
* Molybdenum content of the associated food(s).
*/
molybdenum_mg?: number
/**
* Niacin content of the associated food(s).
*/
niacin_mg?: number
/**
* Pantothenic content of the associated food(s).
*/
pantothenic_acid_mg?: number
/**
* Phosphorus content of the associated food(s).
*/
phosphorus_mg?: number
/**
* Potassium content of the associated food(s).
*/
potassium_mg?: number
/**
* Riboflavin content of the associated food(s).
*/
riboflavin_mg?: number
/**
* Selenium content of the associated food(s).
*/
selenium_mg?: number
/**
* Thiamin content of the associated food(s).
*/
thiamin_mg?: number
/**
* Vitamin A content of the associated food(s).
*/
vitamin_A_mg?: number
/**
* Vitamin B12 content of the associated food(s).
*/
vitamin_B12_mg?: number
/**
* Vitamin B6 content of the associated food(s).
*/
vitamin_B6_mg?: number
/**
* Vitamin C content of the associated food(s).
*/
vitamin_C_mg?: number
/**
* Vitamin D content of the associated food(s).
*/
vitamin_D_mg?: number
/**
* Vitamin D2 content of the associated food(s).
*/
vitamin_D2_mg?: number
/**
* Vitamin D3 content of the associated food(s).
*/
vitamin_D3_mg?: number
/**
* Vitamin E content of the associated food(s).
*/
vitamin_E_mg?: number
/**
* Vitamin K content of the associated food(s).
*/
vitamin_K_mg?: number
/**
* Zinc content of the associated food(s).
*/
zinc_mg?: number
/**
* Cystine content of the associated food(s).
*/
cystine_g?: number
/**
* Histidine content of the associated food(s).
*/
histidine_g?: number
/**
* Isoleucine content of the associated food(s).
*/
isoleucine_g?: number
/**
* Leucine content of the associated food(s).
*/
leucine_g?: number
/**
* Lysine content of the associated food(s).
*/
lysine_g?: number
/**
* Methionine content of the associated food(s).
*/
methionine_g?: number
/**
* Phenylalanine content of the associated food(s).
*/
phenylalanine_g?: number
/**
* Threonine content of the associated food(s).
*/
threonine_g?: number
/**
* Tryptophan content of the associated food(s).
*/
tryptophan_g?: number
/**
* Tyrosine content of the associated food(s).
*/
tyrosine_g?: number
/**
* Valine content of the associated food(s).
*/
valine_g?: number
/**
* Monounsaturated fat content of the associated food(s).
*/
monounsaturated_fat_g?: number
/**
* Polyunsaturated fat content of the associated food(s).
*/
polyunsaturated_fat_g?: number
/**
* Omega3 content of the associated food(s).
*/
omega3_g?: number
/**
* Omega6 content of the associated food(s).
*/
omega6_g?: number
/**
* Starch content of the associated food(s).
*/
starch_g?: number
[k: string]: unknown
}
/**
* Quantity of the food that was consumed, containing information on amount & units in which this was recorded.
*/
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionQuantityYaml {
unit: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionUnitsYaml
amount: number
[k: string]: unknown
}
/**
* Macronutrient information for associated food.
*/
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMacrosYaml {
/**
* Alcohol content of the associated food(s).
*/
alcohol_g?: number
/**
* Calorie content of the associated food(s).
*/
calories?: number
/**
* Carbohydrates content of the associated food(s).
*/
carbohydrates_g?: number
/**
* Cholesterol content of the associated food(s).
*/
cholesterol_mg?: number
/**
* Fat content of the associated food(s).
*/
fat_g?: number
/**
* Fiber content of the associated food(s).
*/
fiber_g?: number
/**
* Net carbs content of the associated food(s).
*/
net_carbohydrates_g?: number
/**
* Protein content of the associated food(s).
*/
protein_g?: number
/**
* Saturated fat content of the associated food(s).
*/
saturated_fat_g?: number
/**
* Sodium content of the associated food(s).
*/
sodium_mg?: number
/**
* Sugar content of the associated food(s).
*/
sugar_g?: number
/**
* Trans fat content of the associated food(s).
*/
trans_fat_g?: number
[k: string]: unknown
}
/**
* Object containing daily summary metadata.
*/
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMetadataYaml {
/**
* The end time of the associated day, in ISO8601 format with microsecond precision. Will always fall on midnight of any given day, and will always be equal to 24h after start_time. TimeZone info will be provided whenever possible. If absent, the time corresponds to the user's local time.
*/
end_time: string
/**
* The start time of the associated day, in ISO8601 format with microsecond precision. Will always fall on midnight of any given day, and will always be equal to 24h before end_time. TimeZone info will be provided whenever possible. If absent, the time corresponds to the user's local time.
*/
start_time: string
timestamp_localization?: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasTimestampLocalizationYaml
[k: string]: unknown
}
/**
* Summative nutritional information for a given day.
*/
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionSummaryYaml {
macros?: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMacrosYaml1
micros?: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMicrosYaml1
/**
* Water consumption of the user for a given day.
*/
water_ml?: number
/**
* Non-water drink consumption of the user for a given day.
*/
drink_ml?: number
[k: string]: unknown
}
/**
* Summary of macronutrient information for a given day.
*/
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMacrosYaml1 {
/**
* Alcohol content of the associated food(s).
*/
alcohol_g?: number
/**
* Calorie content of the associated food(s).
*/
calories?: number
/**
* Carbohydrates content of the associated food(s).
*/
carbohydrates_g?: number
/**
* Cholesterol content of the associated food(s).
*/
cholesterol_mg?: number
/**
* Fat content of the associated food(s).
*/
fat_g?: number
/**
* Fiber content of the associated food(s).
*/
fiber_g?: number
/**
* Net carbs content of the associated food(s).
*/
net_carbohydrates_g?: number
/**
* Protein content of the associated food(s).
*/
protein_g?: number
/**
* Saturated fat content of the associated food(s).
*/
saturated_fat_g?: number
/**
* Sodium content of the associated food(s).
*/
sodium_mg?: number
/**
* Sugar content of the associated food(s).
*/
sugar_g?: number
/**
* Trans fat content of the associated food(s).
*/
trans_fat_g?: number
[k: string]: unknown
}
/**
* Summary of micronutrient information for a given day.
*/
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMicrosYaml1 {
/**
* Biotin content of the associated food(s).
*/
biotin_mg?: number
/**
* Caffeine content of the associated food(s).
*/
caffeine_mg?: number
/**
* Calcium content of the associated food(s).
*/
calcium_mg?: number
/**
* Chloride content of the associated food(s).
*/
chloride_mg?: number
/**
* Chromium content of the associated food(s).
*/
chromium_mg?: number
/**
* Copper content of the associated food(s).
*/
copper_mg?: number
/**
* Folate content of the associated food(s).
*/
folate_mg?: number
/**
* Folic Acid content of the associated food(s).
*/
folic_acid_mg?: number
/**
* Iodine content of the associated food(s).
*/
iodine_mg?: number
/**
* Iron content of the associated food(s).
*/
iron_mg?: number
/**
* Magnesium content of the associated food(s).
*/
magnesium_mg?: number
/**
* Manganese content of the associated food(s).
*/
manganese_mg?: number
/**
* Molybdenum content of the associated food(s).
*/
molybdenum_mg?: number
/**
* Niacin content of the associated food(s).
*/
niacin_mg?: number
/**
* Pantothenic content of the associated food(s).
*/
pantothenic_acid_mg?: number
/**
* Phosphorus content of the associated food(s).
*/
phosphorus_mg?: number
/**
* Potassium content of the associated food(s).
*/
potassium_mg?: number
/**
* Riboflavin content of the associated food(s).
*/
riboflavin_mg?: number
/**
* Selenium content of the associated food(s).
*/
selenium_mg?: number
/**
* Thiamin content of the associated food(s).
*/
thiamin_mg?: number
/**
* Vitamin A content of the associated food(s).
*/
vitamin_A_mg?: number
/**
* Vitamin B12 content of the associated food(s).
*/
vitamin_B12_mg?: number
/**
* Vitamin B6 content of the associated food(s).
*/
vitamin_B6_mg?: number
/**
* Vitamin C content of the associated food(s).
*/
vitamin_C_mg?: number
/**
* Vitamin D content of the associated food(s).
*/
vitamin_D_mg?: number
/**
* Vitamin D2 content of the associated food(s).
*/
vitamin_D2_mg?: number
/**
* Vitamin D3 content of the associated food(s).
*/
vitamin_D3_mg?: number
/**
* Vitamin E content of the associated food(s).
*/
vitamin_E_mg?: number
/**
* Vitamin K content of the associated food(s).
*/
vitamin_K_mg?: number
/**
* Zinc content of the associated food(s).
*/
zinc_mg?: number
/**
* Cystine content of the associated food(s).
*/
cystine_g?: number
/**
* Histidine content of the associated food(s).
*/
histidine_g?: number
/**
* Isoleucine content of the associated food(s).
*/
isoleucine_g?: number
/**
* Leucine content of the associated food(s).
*/
leucine_g?: number
/**
* Lysine content of the associated food(s).
*/
lysine_g?: number
/**
* Methionine content of the associated food(s).
*/
methionine_g?: number
/**
* Phenylalanine content of the associated food(s).
*/
phenylalanine_g?: number
/**
* Threonine content of the associated food(s).
*/
threonine_g?: number
/**
* Tryptophan content of the associated food(s).
*/
tryptophan_g?: number
/**
* Tyrosine content of the associated food(s).
*/
tyrosine_g?: number
/**
* Valine content of the associated food(s).
*/
valine_g?: number
/**
* Monounsaturated fat content of the associated food(s).
*/
monounsaturated_fat_g?: number
/**
* Polyunsaturated fat content of the associated food(s).
*/
polyunsaturated_fat_g?: number
/**
* Omega3 content of the associated food(s).
*/
omega3_g?: number
/**
* Omega6 content of the associated food(s).
*/
omega6_g?: number
/**
* Starch content of the associated food(s).
*/
starch_g?: number
[k: string]: unknown
}
Submitted by hugo697 235 days ago