SDKs
Overview

SDKs

Client libraries อย่างเป็นทางการสำหรับ PBCP

ภาษาสถานะPackage
JavaScript / TypeScriptเร็วๆ นี้@pcampus-studio/sdk
Pythonวางแผน—
Goวางแผน—
Flutter / Dartวางแผนpcampus_sdk (pub.dev)
Rustวางแผนpcampus-sdk (crates.io)

ใช้ REST APIs โดยตรง — ทุก endpoint มีเสถียรภาพและมีเอกสารครบถ้วน

SDK ตัวแรกที่เป็นเป้า คือ Event SDK ฝั่งเซิร์ฟเวอร์ (track() → POST /events) บน backend ของลูกค้า
ไม่ใช่ browser pixel และไม่ฝัง production API key ในหน้าบ้านผู้ซื้อ
วันนี้ทางหลักคือ REST

ใช้ REST API โดยตรง

ทุก Pcampus API เป็น HTTP ปกติที่ใช้ JSON ทุก HTTP client ใช้ได้:

# cURL
curl https://pip.pcampus.co/identity/me \
  -H "Authorization: Bearer $PIP_API_KEY"
// JavaScript — fetch (Node 18+ / browser)
const res = await fetch('https://pip.pcampus.co/identity/me', {
  headers: { Authorization: `Bearer ${process.env.PIP_API_KEY}` },
})
# Python — httpx
import httpx
r = httpx.get('https://pip.pcampus.co/identity/me',
               headers={'Authorization': f"Bearer {api_key}"})
// Flutter / Dart — http package
import 'package:http/http.dart' as http;
 
final response = await http.get(
  Uri.parse('https://pip.pcampus.co/identity/me'),
  headers: {'Authorization': 'Bearer $pipApiKey'},
);
// Rust — reqwest
use reqwest::header::{AUTHORIZATION, HeaderMap, HeaderValue};
 
let mut headers = HeaderMap::new();
headers.insert(
    AUTHORIZATION,
    HeaderValue::from_str(&format!("Bearer {}", pip_api_key))?,
);
 
let client = reqwest::Client::new();
let res = client
    .get("https://pip.pcampus.co/identity/me")
    .headers(headers)
    .send()
    .await?;

หมายเหตุสำหรับ Flutter

Flutter apps ที่ใช้ Firebase Auth สามารถใช้ Connect widget ได้ผ่าน External IdP binding — ดู Connect — External IdP:

import 'package:firebase_auth/firebase_auth.dart';
 
// ดึง Firebase ID token
final token = await FirebaseAuth.instance.currentUser?.getIdToken();
 
// ส่งไป Connect identity exchange
final res = await http.post(
  Uri.parse('https://connect-api.pcampus.co/v1/identity/exchange'),
  headers: {
    'Content-Type': 'application/json',
    'x-tenant-id': 'your-tenant-id',
  },
  body: jsonEncode({
    'provider': 'firebase',
    'identityToken': token,
  }),
);

รับการแจ้งเตือน

เพื่อรับการแจ้งเตือนเมื่อ SDK พร้อมใช้งาน ติดตาม repository pcampus-developers (opens in a new tab) หรืออีเมล support@pcampus.co