Building a Blox Fruits Stock API 🍎
Table Of Contents
- Why I created a Blox Fruits Stock API
- Key Features of the Blox Fruits Stock API
- API Architecture
- API Endpoints
- Public Endpoints
- Data Structure
- Security Implementation
- API Key Authentication
- Master Key System
- Environment Variable Protection
- Technical Implementation
- Custom Fruit Data System
- Price Customization
- Unit Conversion
- Metadata Enrichment
- Development Challenges
- GitHub Integration
- Custom Data Overlay
- Environment Configuration
- Future Plans
- Using the API
- JavaScript Example
- Python Example
- Conclusion
Why I created a Blox Fruits Stock API
As an avid Blox Fruits player, I often found myself wanting real-time information about which fruits were available in the game. The in-game stock changes regularly, and keeping track of available fruits, their prices, and other attributes manually was becoming tedious. I needed a way to:
- Access current stock information programmatically
- Customize pricing and metadata for different fruits
- Easily integrate this data into other applications
This need led me to develop a comprehensive Blox Fruits Stock API—a tool that provides real-time access to game stock information with additional custom data. After several iterations, I released a stable version that has significantly improved my ability to track and share fruit availability.
Key Features of the Blox Fruits Stock API
The API offers several essential functionalities:
- Real-time stock information for both Normal and Mirage servers
- Customized pricing and metadata for each fruit
- Secure API key authentication system
- Admin routes for managing API access
- Detailed fruit information including rarity, type, and Robux value
- Flexible endpoints for querying specific server data
API Architecture
The API follows a clean, RESTful design pattern that makes it easy to integrate with various clients:
- GitHub Integration: Stock data is pulled from a GitHub repository, ensuring it can be easily updated
- Custom Data Overlay: Adds additional information like rarity and Robux pricing to each fruit
- API Key System: Secure authentication for all endpoints
- Environment Configuration: Supports both development and production environments
API Endpoints
The Stock API provides intuitive endpoints for accessing data:
Public Endpoints
GET /api/healthReturns the API’s operational status, useful for monitoring.
GET /api/stock?apiKey=[yourApiKey]Returns complete stock information for both Normal and Mirage stock with custom data.
GET /api/stock/normal?apiKey=[yourApiKey]Returns stock information for the Normal stcok only.
GET /api/stock/mirage?apiKey=[yourApiKey]Returns stock information for the Mirage stock only.
Data Structure
The API returns a comprehensive data structure for each fruit:
{ "name": "Spin-Spin", "price": "7500", "rawLine": "<:SpinFruit:1185094501442797609> Spin-Spin<a:ArrowR:1186305605107974186><:Beli:1186304334493913181>7.5K", "customData": { "robux": 75, "rarity": "common", "type": "natural", "awakening": false }}This structure includes:
- The fruit’s name
- The price in Beli (in-game currency)
- The raw display line (useful for Discord integration)
- Custom data including Robux value, rarity, type, and awakening status
Security Implementation
The API implements a multi-tiered security system:
API Key Authentication
All endpoints require a valid API key to access. This prevents unauthorized usage and allows for usage tracking.
Master Key System
Administrative functions are protected by a master key, ensuring only authorized administrators can manage API keys.
Environment Variable Protection
Sensitive information like GitHub tokens and API keys are stored in environment variables, not in the codebase.
Technical Implementation
The Blox Fruits Stock API is built using modern web technologies:
- Backend: Node.js with Express.js framework
- Data Storage: GitHub repository for stock data, JSON files for development
- Authentication: Custom API key system
- Deployment: Ready for Vercel deployment with serverless functions
Custom Fruit Data System
One of the most powerful features is the ability to customize fruit data:
Price Customization
The API allows for custom pricing of fruits, overriding the default values from the game:
{ "Spin-Spin": { "price": 7500, "robux": 75, "rarity": "common", "type": "natural", "awakening": false }}Unit Conversion
The system intelligently handles unit conversions for clarity:
- Values under 1,000 are shown as is
- Values between 1,000 and 999,999 use the “K” suffix
- Values between 1,000,000 and 999,999,999 use the “M” suffix
- Values over 1,000,000,000 use the “B” suffix
Metadata Enrichment
Each fruit is enriched with additional metadata:
- Rarity: Common, Uncommon, Rare, Legendary, or Mythical
- Type: Natural, Elemental, or Beast
- Awakening: Whether the fruit has an awakened form
- Robux Value: The equivalent Robux value for the fruit
Development Challenges
Creating this API presented several interesting challenges:
GitHub Integration
Fetching and updating data from GitHub required careful implementation:
- Proper authentication with GitHub’s API
- Error handling for network issues
- Rate limiting considerations
Custom Data Overlay
Merging custom data with the base stock information while preserving the original formatting was complex:
- Maintaining the original data structure
- Adding custom fields without breaking existing functionality
- Ensuring data consistency across different requests
Environment Configuration
Supporting both development and production environments required a flexible configuration system:
- Local file-based storage for development
- Environment variables for production
- Conditional logic for different environments
Future Plans
While the current version of the Blox Fruits Stock API is functional, several enhancements are planned:
- Webhook Notifications: Alerts when specific fruits become available
- Historical Data: Tracking fruit availability over time
- Prediction Algorithm: Forecasting when fruits might appear based on historical patterns
- User Preferences: Allowing users to set preferred fruits for notifications
- Mobile App Integration: Direct connection to a companion mobile app
- Rate Limiting: Advanced rate limiting for API protection
Using the API
The API is designed to be easy to integrate with various applications:
JavaScript Example
async function getBloxFruitsStock(apiKey) { try { const response = await fetch(`https://your-api-url.com/api/stock?apiKey=${apiKey}`); const data = await response.json(); return data; } catch (error) { console.error('Error fetching stock data:', error); return null; }}Python Example
import requests
def get_blox_fruits_stock(api_key): try: response = requests.get(f"https://your-api-url.com/api/stock?apiKey={api_key}") return response.json() except Exception as e: print(f"Error fetching stock data: {e}") return NoneConclusion
Building the Blox Fruits Stock API has streamlined my gaming experience and provided a valuable tool for the Blox Fruits community. By creating a central source for real-time fruit availability with enhanced metadata, it’s now easier than ever to track and share information about in-game items.
Whether you’re a casual player looking to find your favorite fruit or a developer building tools for the community, having a dedicated API for stock information can save significant time and enhance the overall gaming experience.