ภาพรวม API สำหรับนักพัฒนา
ภาพรวม API สำหรับนักพัฒนา
Section titled “ภาพรวม API สำหรับนักพัฒนา”REDBLU API ให้การเข้าถึงข้อมูลและการควบคุมระบบทั้งหมดผ่าน RESTful API ที่ออกแบบมาเพื่อความง่ายและประสิทธิภาพ
Base URL และการยืนยันตัวตน
Section titled “Base URL และการยืนยันตัวตน”Base URL
Section titled “Base URL”https://api.redblu.io/v1การยืนยันตัวตน
Section titled “การยืนยันตัวตน”ใช้ API Key ในรูปแบบ Bearer Token:
Authorization: Bearer YOUR_API_KEYContent-Type: application/jsonการรับ API Key
Section titled “การรับ API Key”- เข้าสู่ระบบแดชบอร์ด: https://dashboard.redblu.io
- ไปที่ Settings > API Keys
- คลิก “Generate New Key”
- เก็บ API Key ไว้อย่างปลอดภัย
ผลิตภัณฑ์ที่รองรับ
Section titled “ผลิตภัณฑ์ที่รองรับ”SiloScale API
Section titled “SiloScale API”- การตรวจสอบระดับวัตถุดิบ
- ควบคุมการป้อนและปล่อย
- ข้อมูลเซ็นเซอร์เรียลไทม์
AutoScraper API
Section titled “AutoScraper API”- ควบคุมการเก็บเกี่ยว
- วิเคราะห์ผลผลิต
- จัดการแผนการทำงาน
TeleScraper API
Section titled “TeleScraper API”- ควบคุมระยะไกล
- ข้อมูล IoT และเซ็นเซอร์
- การวิเคราะห์ข้อมูล
AutoScale API
Section titled “AutoScale API”- ข้อมูลการชั่งน้ำหนัก
- ควบคุมระบบบรรจุ
- รายงานคุณภาพ
Response Format
Section titled “Response Format”ทุก API จะตอบกลับในรูปแบบ JSON:
{ "success": true, "data": { "message": "Operation completed successfully" }, "timestamp": "2024-08-05T12:00:00Z", "request_id": "req_abc123"}Error Response
Section titled “Error Response”{ "success": false, "error": { "code": "INVALID_REQUEST", "message": "Invalid parameter: device_id is required", "details": {} }, "timestamp": "2024-08-05T12:00:00Z", "request_id": "req_def456"}HTTP Status Codes
Section titled “HTTP Status Codes”| Code | Description |
|---|---|
| 200 | Success |
| 201 | Created |
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
| 429 | Rate Limited |
| 500 | Internal Server Error |
Rate Limiting
Section titled “Rate Limiting”- Free Tier: 1,000 requests/hour
- Pro Tier: 10,000 requests/hour
- Enterprise: Unlimited
Rate limit headers:
X-RateLimit-Limit: 1000X-RateLimit-Remaining: 999X-RateLimit-Reset: 1691236800SDKs และ Libraries
Section titled “SDKs และ Libraries”JavaScript/Node.js
Section titled “JavaScript/Node.js”npm install @redblu/api-clientimport { RedBluClient } from '@redblu/api-client';
const client = new RedBluClient({ apiKey: 'your-api-key', baseURL: 'https://api.redblu.io/v1'});Python
Section titled “Python”pip install redblu-pythonfrom redblu import RedBluClient
client = RedBluClient(api_key='your-api-key')composer require redblu/php-clientuse RedBlu\Client;
$client = new Client([ 'api_key' => 'your-api-key']);Webhooks
Section titled “Webhooks”รับการแจ้งเตือนเมื่อมีเหตุการณ์สำคัญ:
POST https://your-domain.com/webhookContent-Type: application/jsonX-RedBlu-Signature: sha256=...
{ "event": "device.alert", "device_id": "silo_001", "timestamp": "2024-08-05T12:00:00Z", "data": { "alert_type": "low_level", "current_level": 15, "threshold": 20 }}การทดสอบ API
Section titled “การทดสอบ API”ใช้ cURL
Section titled “ใช้ cURL”curl -X GET \ https://api.redblu.io/v1/devices \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json'ใช้ Postman
Section titled “ใช้ Postman”- Import Collection: https://api.redblu.io/postman/collection.json
- ตั้งค่า Environment Variable:
api_key - เริ่มทดสอบ API endpoints
ใช้ Insomnia
Section titled “ใช้ Insomnia”- Import Workspace: https://api.redblu.io/insomnia/workspace.json
- ตั้งค่า Base Environment
- เริ่มใช้งาน
ตัวอย่างการใช้งาน
Section titled “ตัวอย่างการใช้งาน”ตรวจสอบสถานะอุปกรณ์
Section titled “ตรวจสอบสถานะอุปกรณ์”// Get all devicesconst devices = await client.devices.list();
// Get specific deviceconst device = await client.devices.get('silo_001');
// Get device statusconst status = await client.devices.getStatus('silo_001');ควบคุมอุปกรณ์
Section titled “ควบคุมอุปกรณ์”// Start operationawait client.devices.start('silo_001', { operation: 'feed', amount: 100, rate: 10});
// Stop operationawait client.devices.stop('silo_001');รับข้อมูลเซ็นเซอร์
Section titled “รับข้อมูลเซ็นเซอร์”// Real-time dataconst data = await client.sensors.getRealtime('silo_001');
// Historical dataconst history = await client.sensors.getHistory('silo_001', { from: '2024-08-01T00:00:00Z', to: '2024-08-05T23:59:59Z', interval: '1h'});สำหรับรายละเอียด API แต่ละผลิตภัณฑ์ กรุณาดูหัวข้อถัดไป