.NET client for the Withings Health Data API (OAuth 2.0).
- .NET 8.0, 9.0, or 10.0
dotnet add package Withings.NET
varcredentials=newWithingsCredentials();credentials.SetClientProperties("your_client_id","your_client_secret");credentials.SetCallbackUrl("http://localhost:8585/callback");varauthenticator=newAuthenticator(credentials);// Generate the authorization URL and redirect the uservarurl=authenticator.GetAuthCodeUrl("user.info,user.metrics,user.activity",state);// After the user authorizes, exchange the code for tokensvartoken=awaitauthenticator.GetAccessToken(authorizationCode);// Refresh tokens when they expirevarnewToken=awaitauthenticator.RefreshAccessToken(token.RefreshToken);varclient=newWithingsClient(credentials);// Activity measuresvaractivity=awaitclient.GetActivityMeasures(startDate,endDate,userId,accessToken);// Body measuresvarbody=awaitclient.GetBodyMeasures(userId,startDate,endDate,accessToken);// Sleep summaryvarsleep=awaitclient.GetSleepSummary("2024-01-01","2024-01-31",accessToken);// Sleep measuresvarsleepData=awaitclient.GetSleepMeasures(userId,startDate,endDate,accessToken);// Workoutsvarworkouts=awaitclient.GetWorkouts("2024-01-01","2024-01-31",accessToken);// Intraday activityvarintraday=awaitclient.GetIntraDayActivity(userId,startDate,endDate,accessToken);// HeartvarheartList=awaitclient.GetHeartList(startDate,endDate,accessToken);varrecording=awaitclient.GetHeartRecording(signalId,accessToken);// Uservardevices=awaitclient.GetDevices(accessToken);vargoals=awaitclient.GetGoals(accessToken);// Webhook subscriptionsawaitclient.Subscribe(callbackUrl,appli,accessToken);varsubscriptions=awaitclient.ListSubscriptions(appli,accessToken);awaitclient.RevokeSubscription(callbackUrl,appli,accessToken);dotnet test --filter "TestCategory!=E2E"E2E tests run against the live Withings API. You need to bootstrap OAuth tokens first.
- Create a
.envfile in the project root:
WITHINGS_CLIENT_ID=your_client_id
WITHINGS_CLIENT_SECRET=your_client_secret
WITHINGS_CALLBACK_URL=http://localhost:8585/callback
WITHINGS_REFRESH_TOKEN=
WITHINGS_USER_ID=
- Run the bootstrap script to obtain tokens:
./scripts/bootstrap-token.sh- Run E2E tests:
dotnet test --filter "TestCategory=E2E" -f net10.0The E2E test suite automatically saves new refresh tokens back to .env after each run (Withings refresh tokens are single-use).
| Class | Description |
|---|---|
Authenticator | OAuth 2.0 authorization and token management |
WithingsClient | API client for health data endpoints |
OAuthToken | Token response with access token, refresh token, and user ID |
WithingsApiException | Exception thrown for non-zero API status codes |
See LICENSE for details.