Chuyển đến nội dung

Tài liệu API

Smrt English Client API

API chỉ đọc, trả dữ liệu học viên và lớp học về hệ thống của đơn vị. Mỗi khóa API (API key) chỉ truy cập được dữ liệu của chính đơn vị sở hữu khóa đó.

Mở trang thử nghiệm API

Cách thức hoạt động

Cách một yêu cầu được xử lý.

Hệ thống của đơn vị gửi yêu cầu lấy dữ liệu một học viên hoặc một lớp kèm khóa API riêng, và API trả về dữ liệu ở chế độ chỉ đọc.

Hệ thống của đơn vịPhần mềm quản lý học viên hoặc công cụ báo cáo của đơn vị.
Khóa API của đơn vịĐược gửi kèm mọi yêu cầu và gắn với đơn vị.
Smrt English APICác endpoint chỉ đọc cho học viên và lớp học.
Dữ liệu của đơn vịĐiểm, điểm danh và danh sách lớp ở định dạng JSON.
keyboard_arrow_up

Smrt English API

thumb_up Best Practices

Integration Guidelines

1. Cache Responses

  • Student data doesn't change frequently
  • Consider caching responses for 5-15 minutes
  • Implement cache invalidation when needed

2. Batch Processing

  • If fetching data for multiple students, space out requests
  • Process data asynchronously when possible
  • Consider off-peak hours for large data pulls

3. Error Recovery

  • Implement retry logic with exponential backoff
  • Handle network timeouts gracefully
  • Log errors for debugging

4. Data Handling

  • Validate data structure before processing
  • Handle null values appropriately
  • Check for empty arrays before iterating

Code Examples

PHP Example

<?php
function getStudentData($studentId, $apiKey) {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, "https://smrtenglish.com/smrtapi/v1/student/$studentId");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        "X-API-Key: $apiKey"
    ]);

    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    if ($httpCode === 200) {
        return json_decode($response, true);
    } else {
        // Handle error
        return null;
    }
}

// Load API key from environment variable for security
$apiKey = getenv('SMRT_API_KEY');
$studentId = 12345;
$data = getStudentData($studentId, $apiKey);

if ($data && $data['success']) {
    $student = $data['data']['student'];
    echo "Student: " . $student['name'] . "\n";
    echo "Email: " . $student['email'] . "\n";
}
?>

Python Example

import requests
import os

def get_student_data(student_id, api_key):
    url = f"https://smrtenglish.com/smrtapi/v1/student/{student_id}"
    headers = {
        "X-API-Key": api_key
    }

    response = requests.get(url, headers=headers)

    if response.status_code == 200:
        return response.json()
    else:
        # Handle error
        return None

# Load API key from environment variable for security
api_key = os.environ.get('SMRT_API_KEY')
student_id = 12345
data = get_student_data(student_id, api_key)

if data and data.get('success'):
    student = data['data']['student']
    print(f"Student: {student['name']}")
    print(f"Email: {student['email']}")

JavaScript/Node.js Example

const axios = require('axios');

async function getStudentData(studentId, apiKey) {
    try {
        const response = await axios.get(
            `https://smrtenglish.com/smrtapi/v1/student/${studentId}`,
            {
                headers: {
                    'X-API-Key': apiKey
                }
            }
        );

        if (response.data.success) {
            return response.data.data;
        }
    } catch (error) {
        console.error('API Error:', error.response?.data || error.message);
        return null;
    }
}

// Load API key from environment variable for security
const apiKey = process.env.SMRT_API_KEY;
const studentId = 12345;

getStudentData(studentId, apiKey).then(data => {
    if (data) {
        const student = data.student;
        console.log(`Student: ${student.name}`);
        console.log(`Email: ${student.email}`);
    }
});