0

Post nutrition logs to a provider

by
Published Oct 17, 2025

Used to post nutrition logs to a provider. This endpoint only works for users connected via Fitbit. Returns error for other providers.

Script terra Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Post nutrition logs to a provider
4
 * Used to post nutrition logs to a provider. This endpoint only works for users connected via Fitbit. Returns error for other providers.
5
 */
6
export async function main(auth: RT.Terra, body: Body) {
7
	const url = new URL(`https://api.tryterra.co/v2/nutrition`)
8

9
	const response = await fetch(url, {
10
		method: 'POST',
11
		headers: {
12
			'dev-id': auth.devId,
13
			'Content-Type': 'application/json',
14
			'X-api-key': auth.apiKey
15
		},
16
		body: JSON.stringify(body)
17
	})
18
	if (!response.ok) {
19
		const text = await response.text()
20
		throw new Error(`${response.status} ${text}`)
21
	}
22
	return await response.json()
23
}
24

25
/* eslint-disable */
26
/**
27
 * This file was automatically generated by json-schema-to-typescript.
28
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
29
 * and run json-schema-to-typescript to regenerate this file.
30
 */
31

32
/**
33
 * Enum representing the category the consumed food/meal falls under (i.e. Breakfast/Lunch/Dinner etc).
34
 */
35
export type HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasMealTypeYaml =
36
	| Unknown
37
	| Breakfast
38
	| MorningSnack
39
	| Lunch
40
	| AfternoonSnack
41
	| Dinner
42
	| Snack
43
/**
44
 * Meal type is unknown or could not be determined.
45
 */
46
export type Unknown = 0
47
/**
48
 * Meal consumed in the morning, typically the first meal of the day.
49
 */
50
export type Breakfast = 1
51
/**
52
 * Light meal or snack consumed in the morning, between breakfast and lunch.
53
 */
54
export type MorningSnack = 2
55
/**
56
 * Meal consumed around midday, typically the second meal of the day.
57
 */
58
export type Lunch = 3
59
/**
60
 * Light meal or snack consumed in the afternoon, between lunch and dinner.
61
 */
62
export type AfternoonSnack = 4
63
/**
64
 * Meal consumed in the evening, typically the last main meal of the day.
65
 */
66
export type Dinner = 5
67
/**
68
 * Any light meal or snack consumed at any time, not fitting into main meal categories.
69
 */
70
export type Snack = 6
71
/**
72
 * Represents units used for nutrition measurements
73
 */
74
export type HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionUnitsYaml =
75
	| Unknown1
76
	| Gram
77
	| Teaspoon
78
	| Tablespoon
79
	| Cup
80
	| MediumEgg
81
	| LargeEgg
82
	| SmallEgg
83
	| Milliliter
84
	| Ounce
85
	| Count
86
	| Scoop
87
	| FluidOunce
88
/**
89
 * The unit of measurement is unknown or not specified.
90
 */
91
export type Unknown1 = 0
92
/**
93
 * Measurement in grams, a metric unit of mass.
94
 */
95
export type Gram = 1
96
/**
97
 * Measurement in teaspoons, approximately 5 milliliters.
98
 */
99
export type Teaspoon = 2
100
/**
101
 * Measurement in tablespoons, approximately 15 milliliters.
102
 */
103
export type Tablespoon = 3
104
/**
105
 * Measurement in cups, approximately 240 milliliters.
106
 */
107
export type Cup = 4
108
/**
109
 * Quantity measured in medium-sized eggs.
110
 */
111
export type MediumEgg = 5
112
/**
113
 * Quantity measured in large-sized eggs.
114
 */
115
export type LargeEgg = 6
116
/**
117
 * Quantity measured in small-sized eggs.
118
 */
119
export type SmallEgg = 7
120
/**
121
 * Measurement in milliliters, a metric unit of volume.
122
 */
123
export type Milliliter = 8
124
/**
125
 * Measurement in ounces, approximately 28 grams.
126
 */
127
export type Ounce = 9
128
/**
129
 * Quantity measured by individual count or number of items.
130
 */
131
export type Count = 10
132
/**
133
 * Quantity measured in scoops, typically used for protein powder or supplements.
134
 */
135
export type Scoop = 11
136
/**
137
 * Measurement in fluid ounces, approximately 30 milliliters.
138
 */
139
export type FluidOunce = 12
140
/**
141
 * Indicates whether the timestamps in this payload are localized (LOCAL) or in UTC.
142
 */
143
export type HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasTimestampLocalizationYaml =
144
	0 | 1
145

146
export interface Body {
147
	/**
148
	 * Nutrition entry to post to data provider
149
	 */
150
	data: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionYaml[]
151
	[k: string]: unknown
152
}
153
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionYaml {
154
	/**
155
	 * Information on drinks the user consumed throughout the day.
156
	 */
157
	drink_samples?: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasDrinkSampleYaml[]
158
	/**
159
	 * Information on individual foods consumed throughout a given day.
160
	 */
161
	meals?: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasMealYaml[]
162
	metadata: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMetadataYaml
163
	summary?: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionSummaryYaml
164
	[k: string]: unknown
165
}
166
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasDrinkSampleYaml {
167
	/**
168
	 * 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
169
	 */
170
	timestamp?: string
171
	/**
172
	 * Volume of drink consumed
173
	 */
174
	drink_volume?: number
175
	/**
176
	 * Unit of measurement for the drink
177
	 */
178
	drink_unit?: string
179
	/**
180
	 * Name of drink consumed.
181
	 */
182
	drink_name?: string
183
	[k: string]: unknown
184
}
185
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasMealYaml {
186
	micros: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMicrosYaml
187
	type: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasMealTypeYaml
188
	/**
189
	 * Identifier for food logged by the user.
190
	 */
191
	id: string
192
	/**
193
	 * Timestamp the food is associated with, in ISO8601 format, with microsecond precision.
194
	 */
195
	timestamp: string
196
	quantity: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionQuantityYaml
197
	/**
198
	 * Name of food logged by the user.
199
	 */
200
	name: string
201
	macros: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMacrosYaml
202
	[k: string]: unknown
203
}
204
/**
205
 * Micronutrient information for associated food.
206
 */
207
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMicrosYaml {
208
	/**
209
	 * Biotin content of the associated food(s).
210
	 */
211
	biotin_mg?: number
212
	/**
213
	 * Caffeine content of the associated food(s).
214
	 */
215
	caffeine_mg?: number
216
	/**
217
	 * Calcium content of the associated food(s).
218
	 */
219
	calcium_mg?: number
220
	/**
221
	 * Chloride content of the associated food(s).
222
	 */
223
	chloride_mg?: number
224
	/**
225
	 * Chromium content of the associated food(s).
226
	 */
227
	chromium_mg?: number
228
	/**
229
	 * Copper content of the associated food(s).
230
	 */
231
	copper_mg?: number
232
	/**
233
	 * Folate content of the associated food(s).
234
	 */
235
	folate_mg?: number
236
	/**
237
	 * Folic Acid content of the associated food(s).
238
	 */
239
	folic_acid_mg?: number
240
	/**
241
	 * Iodine content of the associated food(s).
242
	 */
243
	iodine_mg?: number
244
	/**
245
	 * Iron content of the associated food(s).
246
	 */
247
	iron_mg?: number
248
	/**
249
	 * Magnesium content of the associated food(s).
250
	 */
251
	magnesium_mg?: number
252
	/**
253
	 * Manganese content of the associated food(s).
254
	 */
255
	manganese_mg?: number
256
	/**
257
	 * Molybdenum content of the associated food(s).
258
	 */
259
	molybdenum_mg?: number
260
	/**
261
	 * Niacin content of the associated food(s).
262
	 */
263
	niacin_mg?: number
264
	/**
265
	 * Pantothenic content of the associated food(s).
266
	 */
267
	pantothenic_acid_mg?: number
268
	/**
269
	 * Phosphorus content of the associated food(s).
270
	 */
271
	phosphorus_mg?: number
272
	/**
273
	 * Potassium content of the associated food(s).
274
	 */
275
	potassium_mg?: number
276
	/**
277
	 * Riboflavin content of the associated food(s).
278
	 */
279
	riboflavin_mg?: number
280
	/**
281
	 * Selenium content of the associated food(s).
282
	 */
283
	selenium_mg?: number
284
	/**
285
	 * Thiamin content of the associated food(s).
286
	 */
287
	thiamin_mg?: number
288
	/**
289
	 * Vitamin A content of the associated food(s).
290
	 */
291
	vitamin_A_mg?: number
292
	/**
293
	 * Vitamin B12 content of the associated food(s).
294
	 */
295
	vitamin_B12_mg?: number
296
	/**
297
	 * Vitamin B6 content of the associated food(s).
298
	 */
299
	vitamin_B6_mg?: number
300
	/**
301
	 * Vitamin C content of the associated food(s).
302
	 */
303
	vitamin_C_mg?: number
304
	/**
305
	 * Vitamin D content of the associated food(s).
306
	 */
307
	vitamin_D_mg?: number
308
	/**
309
	 * Vitamin D2 content of the associated food(s).
310
	 */
311
	vitamin_D2_mg?: number
312
	/**
313
	 * Vitamin D3 content of the associated food(s).
314
	 */
315
	vitamin_D3_mg?: number
316
	/**
317
	 * Vitamin E content of the associated food(s).
318
	 */
319
	vitamin_E_mg?: number
320
	/**
321
	 * Vitamin K content of the associated food(s).
322
	 */
323
	vitamin_K_mg?: number
324
	/**
325
	 * Zinc content of the associated food(s).
326
	 */
327
	zinc_mg?: number
328
	/**
329
	 * Cystine content of the associated food(s).
330
	 */
331
	cystine_g?: number
332
	/**
333
	 * Histidine content of the associated food(s).
334
	 */
335
	histidine_g?: number
336
	/**
337
	 * Isoleucine content of the associated food(s).
338
	 */
339
	isoleucine_g?: number
340
	/**
341
	 * Leucine content of the associated food(s).
342
	 */
343
	leucine_g?: number
344
	/**
345
	 * Lysine content of the associated food(s).
346
	 */
347
	lysine_g?: number
348
	/**
349
	 * Methionine content of the associated food(s).
350
	 */
351
	methionine_g?: number
352
	/**
353
	 * Phenylalanine content of the associated food(s).
354
	 */
355
	phenylalanine_g?: number
356
	/**
357
	 * Threonine content of the associated food(s).
358
	 */
359
	threonine_g?: number
360
	/**
361
	 * Tryptophan content of the associated food(s).
362
	 */
363
	tryptophan_g?: number
364
	/**
365
	 * Tyrosine content of the associated food(s).
366
	 */
367
	tyrosine_g?: number
368
	/**
369
	 * Valine content of the associated food(s).
370
	 */
371
	valine_g?: number
372
	/**
373
	 * Monounsaturated fat content of the associated food(s).
374
	 */
375
	monounsaturated_fat_g?: number
376
	/**
377
	 * Polyunsaturated fat content of the associated food(s).
378
	 */
379
	polyunsaturated_fat_g?: number
380
	/**
381
	 * Omega3 content of the associated food(s).
382
	 */
383
	omega3_g?: number
384
	/**
385
	 * Omega6 content of the associated food(s).
386
	 */
387
	omega6_g?: number
388
	/**
389
	 * Starch content of the associated food(s).
390
	 */
391
	starch_g?: number
392
	[k: string]: unknown
393
}
394
/**
395
 * Quantity of the food that was consumed, containing information on amount & units in which this was recorded.
396
 */
397
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionQuantityYaml {
398
	unit: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionUnitsYaml
399
	amount: number
400
	[k: string]: unknown
401
}
402
/**
403
 * Macronutrient information for associated food.
404
 */
405
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMacrosYaml {
406
	/**
407
	 * Alcohol content of the associated food(s).
408
	 */
409
	alcohol_g?: number
410
	/**
411
	 * Calorie content of the associated food(s).
412
	 */
413
	calories?: number
414
	/**
415
	 * Carbohydrates content of the associated food(s).
416
	 */
417
	carbohydrates_g?: number
418
	/**
419
	 * Cholesterol content of the associated food(s).
420
	 */
421
	cholesterol_mg?: number
422
	/**
423
	 * Fat content of the associated food(s).
424
	 */
425
	fat_g?: number
426
	/**
427
	 * Fiber content of the associated food(s).
428
	 */
429
	fiber_g?: number
430
	/**
431
	 * Net carbs content of the associated food(s).
432
	 */
433
	net_carbohydrates_g?: number
434
	/**
435
	 * Protein content of the associated food(s).
436
	 */
437
	protein_g?: number
438
	/**
439
	 * Saturated fat content of the associated food(s).
440
	 */
441
	saturated_fat_g?: number
442
	/**
443
	 * Sodium content of the associated food(s).
444
	 */
445
	sodium_mg?: number
446
	/**
447
	 * Sugar content of the associated food(s).
448
	 */
449
	sugar_g?: number
450
	/**
451
	 * Trans fat content of the associated food(s).
452
	 */
453
	trans_fat_g?: number
454
	[k: string]: unknown
455
}
456
/**
457
 * Object containing daily summary metadata.
458
 */
459
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMetadataYaml {
460
	/**
461
	 * 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.
462
	 */
463
	end_time: string
464
	/**
465
	 * 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.
466
	 */
467
	start_time: string
468
	timestamp_localization?: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasTimestampLocalizationYaml
469
	[k: string]: unknown
470
}
471
/**
472
 * Summative nutritional information for a given day.
473
 */
474
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionSummaryYaml {
475
	macros?: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMacrosYaml1
476
	micros?: HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMicrosYaml1
477
	/**
478
	 * Water consumption of the user for a given day.
479
	 */
480
	water_ml?: number
481
	/**
482
	 * Non-water drink consumption of the user for a given day.
483
	 */
484
	drink_ml?: number
485
	[k: string]: unknown
486
}
487
/**
488
 * Summary of macronutrient information for a given day.
489
 */
490
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMacrosYaml1 {
491
	/**
492
	 * Alcohol content of the associated food(s).
493
	 */
494
	alcohol_g?: number
495
	/**
496
	 * Calorie content of the associated food(s).
497
	 */
498
	calories?: number
499
	/**
500
	 * Carbohydrates content of the associated food(s).
501
	 */
502
	carbohydrates_g?: number
503
	/**
504
	 * Cholesterol content of the associated food(s).
505
	 */
506
	cholesterol_mg?: number
507
	/**
508
	 * Fat content of the associated food(s).
509
	 */
510
	fat_g?: number
511
	/**
512
	 * Fiber content of the associated food(s).
513
	 */
514
	fiber_g?: number
515
	/**
516
	 * Net carbs content of the associated food(s).
517
	 */
518
	net_carbohydrates_g?: number
519
	/**
520
	 * Protein content of the associated food(s).
521
	 */
522
	protein_g?: number
523
	/**
524
	 * Saturated fat content of the associated food(s).
525
	 */
526
	saturated_fat_g?: number
527
	/**
528
	 * Sodium content of the associated food(s).
529
	 */
530
	sodium_mg?: number
531
	/**
532
	 * Sugar content of the associated food(s).
533
	 */
534
	sugar_g?: number
535
	/**
536
	 * Trans fat content of the associated food(s).
537
	 */
538
	trans_fat_g?: number
539
	[k: string]: unknown
540
}
541
/**
542
 * Summary of micronutrient information for a given day.
543
 */
544
export interface HttpsRawGithubusercontentComTryterraOpenapiRefsHeadsV5UpdateSchemasNutritionMicrosYaml1 {
545
	/**
546
	 * Biotin content of the associated food(s).
547
	 */
548
	biotin_mg?: number
549
	/**
550
	 * Caffeine content of the associated food(s).
551
	 */
552
	caffeine_mg?: number
553
	/**
554
	 * Calcium content of the associated food(s).
555
	 */
556
	calcium_mg?: number
557
	/**
558
	 * Chloride content of the associated food(s).
559
	 */
560
	chloride_mg?: number
561
	/**
562
	 * Chromium content of the associated food(s).
563
	 */
564
	chromium_mg?: number
565
	/**
566
	 * Copper content of the associated food(s).
567
	 */
568
	copper_mg?: number
569
	/**
570
	 * Folate content of the associated food(s).
571
	 */
572
	folate_mg?: number
573
	/**
574
	 * Folic Acid content of the associated food(s).
575
	 */
576
	folic_acid_mg?: number
577
	/**
578
	 * Iodine content of the associated food(s).
579
	 */
580
	iodine_mg?: number
581
	/**
582
	 * Iron content of the associated food(s).
583
	 */
584
	iron_mg?: number
585
	/**
586
	 * Magnesium content of the associated food(s).
587
	 */
588
	magnesium_mg?: number
589
	/**
590
	 * Manganese content of the associated food(s).
591
	 */
592
	manganese_mg?: number
593
	/**
594
	 * Molybdenum content of the associated food(s).
595
	 */
596
	molybdenum_mg?: number
597
	/**
598
	 * Niacin content of the associated food(s).
599
	 */
600
	niacin_mg?: number
601
	/**
602
	 * Pantothenic content of the associated food(s).
603
	 */
604
	pantothenic_acid_mg?: number
605
	/**
606
	 * Phosphorus content of the associated food(s).
607
	 */
608
	phosphorus_mg?: number
609
	/**
610
	 * Potassium content of the associated food(s).
611
	 */
612
	potassium_mg?: number
613
	/**
614
	 * Riboflavin content of the associated food(s).
615
	 */
616
	riboflavin_mg?: number
617
	/**
618
	 * Selenium content of the associated food(s).
619
	 */
620
	selenium_mg?: number
621
	/**
622
	 * Thiamin content of the associated food(s).
623
	 */
624
	thiamin_mg?: number
625
	/**
626
	 * Vitamin A content of the associated food(s).
627
	 */
628
	vitamin_A_mg?: number
629
	/**
630
	 * Vitamin B12 content of the associated food(s).
631
	 */
632
	vitamin_B12_mg?: number
633
	/**
634
	 * Vitamin B6 content of the associated food(s).
635
	 */
636
	vitamin_B6_mg?: number
637
	/**
638
	 * Vitamin C content of the associated food(s).
639
	 */
640
	vitamin_C_mg?: number
641
	/**
642
	 * Vitamin D content of the associated food(s).
643
	 */
644
	vitamin_D_mg?: number
645
	/**
646
	 * Vitamin D2 content of the associated food(s).
647
	 */
648
	vitamin_D2_mg?: number
649
	/**
650
	 * Vitamin D3 content of the associated food(s).
651
	 */
652
	vitamin_D3_mg?: number
653
	/**
654
	 * Vitamin E content of the associated food(s).
655
	 */
656
	vitamin_E_mg?: number
657
	/**
658
	 * Vitamin K content of the associated food(s).
659
	 */
660
	vitamin_K_mg?: number
661
	/**
662
	 * Zinc content of the associated food(s).
663
	 */
664
	zinc_mg?: number
665
	/**
666
	 * Cystine content of the associated food(s).
667
	 */
668
	cystine_g?: number
669
	/**
670
	 * Histidine content of the associated food(s).
671
	 */
672
	histidine_g?: number
673
	/**
674
	 * Isoleucine content of the associated food(s).
675
	 */
676
	isoleucine_g?: number
677
	/**
678
	 * Leucine content of the associated food(s).
679
	 */
680
	leucine_g?: number
681
	/**
682
	 * Lysine content of the associated food(s).
683
	 */
684
	lysine_g?: number
685
	/**
686
	 * Methionine content of the associated food(s).
687
	 */
688
	methionine_g?: number
689
	/**
690
	 * Phenylalanine content of the associated food(s).
691
	 */
692
	phenylalanine_g?: number
693
	/**
694
	 * Threonine content of the associated food(s).
695
	 */
696
	threonine_g?: number
697
	/**
698
	 * Tryptophan content of the associated food(s).
699
	 */
700
	tryptophan_g?: number
701
	/**
702
	 * Tyrosine content of the associated food(s).
703
	 */
704
	tyrosine_g?: number
705
	/**
706
	 * Valine content of the associated food(s).
707
	 */
708
	valine_g?: number
709
	/**
710
	 * Monounsaturated fat content of the associated food(s).
711
	 */
712
	monounsaturated_fat_g?: number
713
	/**
714
	 * Polyunsaturated fat content of the associated food(s).
715
	 */
716
	polyunsaturated_fat_g?: number
717
	/**
718
	 * Omega3 content of the associated food(s).
719
	 */
720
	omega3_g?: number
721
	/**
722
	 * Omega6 content of the associated food(s).
723
	 */
724
	omega6_g?: number
725
	/**
726
	 * Starch content of the associated food(s).
727
	 */
728
	starch_g?: number
729
	[k: string]: unknown
730
}
731