A TypeScript client for the Habitify API with complete type safety and modern developer experience.
- π₯ TypeScript first - Full type safety with comprehensive type definitions
- π Modern SDK - Built with axios and modern JavaScript patterns
- π Complete API coverage - All Habitify API endpoints supported
- π‘οΈ Built-in validation - Request/response validation with meaningful errors
- π― Tree-shakeable - Import only what you need for optimal bundle size
- π Well documented - JSDoc comments and comprehensive examples
npm install @sargonpiraev/habitify-api-client
Before using the client, you'll need a Habitify API key:
- Open Habitify app on your mobile device
- Go to Settings β Account β API
- Generate new API key
- Save API key for use in your application
- Node.js >= v18.0.0
- Habitify API key
- npm >= 8.0.0
import { HabitifyApiClient } from '@sargonpiraev/habitify-api-client'
// Create client with API key
const client = new HabitifyApiClient('your-api-key')
// Get today's habits
const habits = await client.getJournal()
// Update habit status
await client.updateHabitStatus({
habit_id: 'habit-123',
status: 'completed',
target_date: '2025-01-15',
})
// Add a workout log
await client.addLog({
habit_id: 'habit-456',
unit_type: 'rep',
value: 50,
target_date: '2025-01-15',
})
console.log(`Found ${habits.length} habits for today`)
const client = new HabitifyApiClient('your-api-key')
// The client uses sensible defaults but can be customized
const client = new HabitifyApiClient('your-api-key')
// Custom timeout and base URL are handled internally
// Default timeout: 30 seconds
// Default base URL: https://api.habitify.me
// Get habits for today
const todayHabits = await client.getJournal()
// Get habits for specific date
const dateHabits = await client.getJournal({
target_date: '2025-01-15',
order_by: 'priority',
})
// Get habit status
const status = await client.getHabitStatus({
habit_id: 'habit-123',
target_date: '2025-01-15',
})
// Update habit status
await client.updateHabitStatus({
habit_id: 'habit-123',
status: 'completed',
})
// Get logs for a habit
const logs = await client.getLogs({
habit_id: 'habit-123',
from: '2025-01-01',
to: '2025-01-31',
})
// Add new log entry
await client.addLog({
habit_id: 'habit-123',
unit_type: 'min',
value: 30,
target_date: '2025-01-15',
})
// Delete specific log
await client.deleteLog({
habit_id: 'habit-123',
log_id: 'log-456',
})
// Get mood entries
const moods = await client.getMoods({
target_date: '2025-01-15',
})
// Create mood entry
await client.createMood({
value: 4, // 1-5 scale
created_at: new Date().toISOString(),
})
// Update mood
await client.updateMood({
mood_id: 'mood-123',
value: 5,
created_at: new Date().toISOString(),
})
// For maximum flexibility, use raw HTTP methods
const customData = await client.get('/custom-endpoint', { param1: 'value' })
await client.post('/custom-endpoint', { data: 'value' })
await client.put('/custom-endpoint', { data: 'value' })
await client.delete('/custom-endpoint')
All methods return promises and include comprehensive error handling.
new HabitifyApiClient(apiKey: string)
- Create client instance
getJournal(params?)
- Get habits for a date with optional filteringgetHabitStatus(params)
- Get habit status for specific dateupdateHabitStatus(params)
- Update habit completion status
getLogs(params)
- Get logs for habit with date rangeaddLog(params)
- Add new log entry with value and unitdeleteLog(params)
- Delete specific log by IDdeleteLogs(params)
- Delete logs within date range
getMoods(params?)
- Get mood entries with optional date filtergetMood(params)
- Get specific mood by IDcreateMood(params)
- Create new mood entryupdateMood(params)
- Update existing mooddeleteMood(params)
- Delete mood entry
getAreas()
- Get all habit areas/categories
See the Habitify API documentation for complete endpoint reference.
try {
const habits = await client.getJournal()
} catch (error) {
if (error.response?.status === 401) {
console.error('Invalid API key')
} else if (error.response?.status === 429) {
console.error('Rate limit exceeded')
} else {
console.error('API error:', error.message)
}
}
Coming Soon π
- Enhanced Type Safety: Additional validation and type guards
- Response Caching: Intelligent caching for frequently accessed data
- Batch Operations: Support for bulk API operations
- Rate Limiting: Built-in rate limiting and retry logic
- Offline Support: Offline-first capabilities with sync
- React Hooks: React hooks package for easier integration
Completed β
- Full API Coverage: Complete Habitify API integration
- Type Safety: Comprehensive TypeScript types
- Error Handling: Structured error management
- Tree Shaking: Optimized bundle size with selective imports
Community Requests π
Have an idea for Habitify API Client? Open an issue or contribute to our roadmap!
- MCP Servers - integrate with Claude and other AI tools
- Automation Scripts - sync habits with other productivity services
- Analytics Tools - analyze your habit data and progress
- Mobile Apps - build custom habit tracking applications
- Web Dashboards - visualize your habit progress and insights
This client is designed specifically for building MCP (Model Context Protocol) servers:
// Example MCP server integration
import { HabitifyApiClient } from '@sargonpiraev/habitify-api-client'
const habitify = new HabitifyApiClient(process.env.HABITIFY_API_KEY)
// Use in your MCP server tools
async function getHabitsForAI() {
const habits = await habitify.getJournal()
return habits.map((h) => `${h.name}: ${h.status || 'not started'}`)
}
Hi! I'm Sargon Piraev, a software engineer passionate about API integrations and developer tools. I create open-source API clients to help developers integrate with their favorite services more easily.
Your support helps me continue developing and maintaining these tools, and motivates me to create new integrations that make developer workflows even more efficient! π
- π Visit sargonpiraev.com
- π§ Email: [email protected]
- π¬ Join Discord