Depends on YAZIO’s private API
Expect breaking changes at any time
go get github.com/controlado/go-yazio
Authenticate
const (
username = "[email protected]"
password = "superStrongPass"
)
var (
ctx = context.Background()
)
api, err := yazio.New()
if err != nil {
log.Fatalf("building yazio api: %v", err)
}
cred := yazio.NewPasswordCred(username, password)
user, err := api.Login(ctx, cred)
if err != nil {
// yazio.ErrRequestingToYazio
// yazio.ErrDecodingResponse
// yazio.ErrInvalidCredentials
log.Fatalf("fetching user from api: %v", err)
}
Refresh session
userToken := user.Token()
// userToken.String()
// Token(Expired)
if userToken.IsExpired() {
if err := api.Refresh(ctx, user); err != nil {
// yazio.ErrRequestingToYazio
// yazio.ErrDecodingResponse
log.Fatalf("refreshing user token: %v", err)
}
}
Get user data
userData, err := user.Data(ctx)
if err != nil {
// yazio.ErrExpiredToken
// yazio.ErrRequestingToYazio
// yazio.ErrDecodingResponse
log.Fatalf("fetching user data from api: %v", err)
}
// userData.String()
// User(João da Silva)
sinceRegist := userData.SinceRegist()
// sinceRegist.String()
// 1 June 2023 - 1 December 2023 (183 days)
userMacros, err := user.Macros(ctx, sinceRegist)
if err != nil {
// yazio.ErrExpiredToken
// yazio.ErrRequestingToYazio
// yazio.ErrDecodingResponse
log.Fatalf("fetching user macros intakes (since regist): %v", err)
}
// userMacros.Average().String()
// Average (1278 days)
// Energy: 1700.0kcal
// Carb: 150.0g
// Fat: 40.0g
// Protein: 180.0g
waterIntakes, err := user.Intake(ctx, intake.Water, sinceRegist)
if err != nil {
// yazio.ErrExpiredToken
// yazio.ErrRequestingToYazio
// yazio.ErrDecodingResponse
log.Fatalf("fetching user water intakes (since regist): %v", err)
}
// waterIntakes.Average().String()
// 320 days: 2223.0ml
Enter and register new food (product)
var (
foodName = "Banana"
foodCat = food.Miscellaneous
foodNuts = food.Nutrients{ // required nutrients
intake.Energy: 0.1,
intake.Fat: 0.1,
intake.Protein: 0.1,
intake.Carb: 0.1,
}
)
newFood, err := food.New(foodName, foodCat, foodNuts)
if err != nil { // food.ErrInvalidName
log.Fatalf("creating a new food: %v", err)
}
if err := user.AddFood(ctx, newFood, visibility.PrivateFood); err != nil {
// yazio.ErrExpiredToken
// yazio.ErrRequestingToYazio
// food.ErrMissingNutrients
// food.ErrAlreadyExists
log.Fatalf("adding new food %s: %v", newFood, err)
}
var (
entryServing = food.Serving{Kind: food.Portion, Amount: 100}
)
if err := user.EntryFood(ctx, meal.Dinner, newFood.ID, entryServing); err != nil {
// yazio.ErrExpiredToken
// yazio.ErrRequestingToYazio
log.Fatalf("entering new food %s: %v", newFood, err)
}
- Login with password
- Register food to account
- Retrieve user profile & nutrition stats
- Zero external deps beyond the Go standard library
- Context/timeout aware
- No affiliation with YAZIO GmbH
- YAZIO is a trademark of YAZIO GmbH
- As-is without warranty (MIT License)
- Use at your own risk: reverse-engineering may violate ToS
Contributions are welcome
Please open an issue or pull request
MIT – see LICENSE
for full text.