SendGrid Connector
เชื่อมต่อบัญชี SendGrid ของคุณกับ Brevo ผ่าน Tajo เพื่อการย้ายโครงสร้างพื้นฐานอีเมล การซิงค์ผู้ติดต่อ การโอนข้อมูลแคมเปญ และ engagement analytics ที่รวมกันบนทั้งสองแพลตฟอร์ม
ภาพรวม
| คุณสมบัติ | ค่า |
|---|---|
| แพลตฟอร์ม | SendGrid (Twilio) |
| หมวดหมู่ | การตลาด |
| ความซับซ้อนในการตั้งค่า | ง่าย |
| การผสานรวมอย่างเป็นทางการ | ใช่ |
| ข้อมูลที่ซิงค์ | ผู้ติดต่อ แคมเปญ Transactional Email เหตุการณ์ |
| API Base URL | https://api.sendgrid.com/v3 |
ฟีเจอร์
- การย้ายผู้ติดต่อ - ย้าย SendGrid Marketing contacts ไปยัง Brevo พร้อม custom fields
- การซิงค์ transactional email - ติดตามเหตุการณ์ transactional email สำหรับรายงานที่รวมกัน
- ข้อมูลแคมเปญ - ซิงค์ข้อมูลประสิทธิภาพแคมเปญ Single Send และ Automation
- Event webhooks - ส่งต่อเหตุการณ์อีเมล (delivered, opened, clicked, bounced) ไปยัง Brevo
- การซิงค์ Suppression - ย้ายรายการ bounce, block และ unsubscribe สำหรับความสอดคล้อง
- การย้าย Template - ส่งออก Dynamic Transactional Templates สำหรับใช้ใน Brevo
- การยืนยัน Sender - ซิงค์ตัวตน sender ที่ได้รับการยืนยันและการยืนยันตัวตน domain
- การซิงค์สถิติ - นำเข้าสถิติ engagement ย้อนหลังไปยัง Brevo attributes
ข้อกำหนดเบื้องต้น
ก่อนเริ่มต้น ตรวจสอบให้แน่ใจว่าคุณมี:
- บัญชี SendGrid (Free, Essentials, Pro หรือ Premier)
- SendGrid API key ที่มีสิทธิ์ที่จำเป็น
- บัญชี Brevo ที่มีสิทธิ์เข้าถึง API
- บัญชี Tajo
การยืนยันตัวตน
การยืนยันตัวตนด้วย API Key
SendGrid ใช้การยืนยันตัวตนด้วย bearer token
curl https://api.sendgrid.com/v3/marketing/contacts \ -H "Authorization: Bearer SG.YOUR_API_KEY" \ -H "Content-Type: application/json"สร้าง API keys ใน SendGrid Settings > API Keys พร้อมระดับสิทธิ์เฉพาะ:
- Full Access - การเข้าถึง API แบบครบถ้วน
- Restricted Access - การควบคุมสิทธิ์แบบละเอียด
- Billing Access - การดำเนินการเฉพาะการเรียกเก็บเงิน
สิทธิ์ที่จำเป็น
Marketing: Full Access - Contacts (read) - Single Sends (read) - Automations (read)Mail Send: Full Access - Mail Send (read)Stats: Read AccessSuppressions: Read AccessTracking: Read Accessความปลอดภัย API Key
SendGrid API keys จะแสดงเพียงครั้งเดียวเมื่อสร้าง เก็บอย่างปลอดภัย หากสูญหายต้องสร้าง key ใหม่
การกำหนดค่า
การตั้งค่าพื้นฐาน
connectors: sendgrid: enabled: true api_key: "${SENDGRID_API_KEY}"
# Data sync options sync: contacts: true campaigns: true transactional: true suppressions: true statistics: true
# List mapping to Brevo list_mapping: "All Contacts": 60 "Newsletter": 61 "Transactional": 62การแมปฟิลด์
แมปฟิลด์ผู้ติดต่อ SendGrid กับแอตทริบิวต์ผู้ติดต่อ Brevo:
การแมปเริ่มต้น
| Parameter | Type | Description |
|---|---|---|
email required | string | ที่อยู่อีเมลผู้ติดต่อ (unique identifier) |
first_name optional | string | แมปกับแอตทริบิวต์ FIRSTNAME |
last_name optional | string | แมปกับแอตทริบิวต์ LASTNAME |
phone_number optional | string | แมปกับแอตทริบิวต์ SMS |
city optional | string | เมืองของผู้ติดต่อ |
country optional | string | ประเทศของผู้ติดต่อ |
custom_fields optional | object | คู่ key-value ของ custom fields |
list_ids optional | array | สมาชิกรายการ SendGrid |
การแมป Custom Field
field_mapping: # Standard fields email: email first_name: FIRSTNAME last_name: LASTNAME phone_number: SMS
# Location fields city: CITY state_province_region: STATE country: COUNTRY postal_code: POSTAL_CODE
# Engagement metrics avg_open_rate: AVG_OPEN_RATE avg_click_rate: AVG_CLICK_RATE
# Custom fields custom_fields.company: COMPANY_NAME custom_fields.plan: PLAN_TYPEAPI Endpoints
Marketing Contacts
| เมธอด | Endpoint | คำอธิบาย |
|---|---|---|
PUT | /v3/marketing/contacts | เพิ่มหรืออัปเดตผู้ติดต่อ |
POST | /v3/marketing/contacts/search | ค้นหาผู้ติดต่อ |
GET | /v3/marketing/contacts/count | ดึงจำนวนผู้ติดต่อ |
POST | /v3/marketing/contacts/exports | ส่งออกผู้ติดต่อ |
DELETE | /v3/marketing/contacts | ลบผู้ติดต่อ |
GET | /v3/marketing/lists | แสดงรายการ contact lists ทั้งหมด |
Transactional Email (Mail Send)
| เมธอด | Endpoint | คำอธิบาย |
|---|---|---|
POST | /v3/mail/send | ส่งอีเมล |
GET | /v3/templates | แสดงรายการ Dynamic Templates |
GET | /v3/templates/{id} | ดึงรายละเอียด template |
แคมเปญ (Single Sends)
| เมธอด | Endpoint | คำอธิบาย |
|---|---|---|
GET | /v3/marketing/singlesends | แสดงรายการ Single Sends |
GET | /v3/marketing/singlesends/{id} | ดึงรายละเอียด Single Send |
GET | /v3/marketing/automations | แสดงรายการ Automations |
สถิติ
| เมธอด | Endpoint | คำอธิบาย |
|---|---|---|
GET | /v3/stats | ดึงสถิติอีเมลทั่วโลก |
GET | /v3/categories/stats | ดึงสถิติตามหมวดหมู่ |
GET | /v3/marketing/stats/singlesends | ดึงสถิติ Single Send |
Suppressions
| เมธอด | Endpoint | คำอธิบาย |
|---|---|---|
GET | /v3/suppression/bounces | แสดงรายการอีเมล bounce |
GET | /v3/suppression/blocks | แสดงรายการอีเมลที่ถูก block |
GET | /v3/suppression/spam_reports | แสดงรายการการรายงาน spam |
GET | /v3/suppression/unsubscribes | แสดงรายการการยกเลิกสมัครทั่วโลก |
เหตุการณ์
เหตุการณ์อีเมล (ผ่าน Event Webhook)
| เหตุการณ์ | Trigger | กรณีการใช้งาน |
|---|---|---|
processed | SendGrid รับอีเมลแล้ว | การยืนยันการส่ง |
delivered | ส่งอีเมลถึงผู้รับแล้ว | การติดตามการส่ง |
open | เปิดอีเมลแล้ว | การให้คะแนน engagement |
click | คลิกลิงก์แล้ว | การติดตามความสนใจ |
bounce | อีเมล bounce | การดูแล list |
dropped | ระงับอีเมลแล้ว | การตรวจสอบความสอดคล้อง |
deferred | ชะลอการส่งแล้ว | การตรวจสอบการลองใหม่ |
spam_report | ถูกทำเครื่องหมายว่าเป็น spam | การจัดการชื่อเสียง |
unsubscribe | ยกเลิกสมัครผ่านลิงก์ | การซิงค์การตั้งค่า |
ตัวอย่างโค้ด
เริ่มต้น Connector
import { TajoClient } from '@tajo/sdk';
const tajo = new TajoClient({ apiKey: process.env.TAJO_API_KEY, brevoApiKey: process.env.BREVO_API_KEY});
// Connect SendGridawait tajo.connectors.connect('sendgrid', { apiKey: process.env.SENDGRID_API_KEY});ย้ายผู้ติดต่อไปยัง Brevo
// Full contact migration from SendGrid to Brevoawait tajo.connectors.sync('sendgrid', { type: 'full', resources: ['contacts', 'suppressions'], options: { includeCustomFields: true, migrateListMemberships: true, migrateSuppressions: true }});
// Check migration statusconst status = await tajo.connectors.status('sendgrid');console.log(status);// {// connected: true,// lastSync: '2024-01-15T10:30:00Z',// contactsMigrated: 45000,// suppressionsSynced: 3200,// listsMapped: 8// }ส่งต่อเหตุการณ์อีเมล
// Handle SendGrid Event Webhookapp.post('/webhooks/sendgrid', async (req, res) => { const signature = req.get('X-Twilio-Email-Event-Webhook-Signature');
// Verify webhook signature (ECDSA) if (!verifySendGridSignature(req.body, signature)) { return res.status(401).send('Unauthorized'); }
// Process batch of events for (const event of req.body) { await tajo.connectors.handleWebhook('sendgrid', { type: event.event, email: event.email, timestamp: event.timestamp, payload: event }); }
res.status(200).send('OK');});ขีดจำกัดอัตรา
Rate limits ของ SendGrid API:
| Endpoint | ขีดจำกัด | รายละเอียด |
|---|---|---|
Mail Send (/v3/mail/send) | ขึ้นอยู่กับแผน | ฟรี: 100/วัน, Essentials: ตามแผน |
| Marketing Contacts PUT | 3 คำขอ/วินาที | Batch สูงสุด 30,000 ผู้ติดต่อ |
| Marketing Contacts Search | 50 คำขอ/วินาที | ต่อ API key |
| General API | 1,000 คำขอ/วินาที | ต่อ API key |
| Event Webhook | Batch delivery | สูงสุด 1,000 เหตุการณ์ต่อ POST |
ขีดจำกัด Mail Send
ขีดจำกัด Mail Send ขึ้นอยู่กับแผน SendGrid ของคุณ บัญชีฟรีถูกจำกัดที่ 100 อีเมล/วัน ตรวจสอบรายละเอียดแผนของคุณสำหรับขีดจำกัดการส่งที่แน่นอน
การแก้ไขปัญหา
ปัญหาทั่วไป
| ปัญหา | สาเหตุ | วิธีแก้ |
|---|---|---|
| 401 Unauthorized | API key ไม่ถูกต้อง | ตรวจสอบ API key ใน SendGrid Settings |
| 403 Forbidden | สิทธิ์ API key ไม่เพียงพอ | สร้าง key ใหม่พร้อม scopes ที่จำเป็น |
| Contact export pending | กำลังประมวลผลชุดข้อมูลขนาดใหญ่ | Poll export status endpoint จนกว่าจะเสร็จสมบูรณ์ |
| Suppression sync ไม่สมบูรณ์ | ต้องใช้ pagination | ใช้ pagination พร้อมพารามิเตอร์ offset |
| ไม่ได้รับ Event webhook | URL ไม่ได้รับการยืนยัน | ทำการยืนยัน webhook URL ให้สมบูรณ์ใน SendGrid |
โหมด Debug
เปิดใช้งาน verbose logging:
connectors: sendgrid: debug: true log_level: verbose log_webhooks: trueทดสอบการเชื่อมต่อ
tajo connectors test sendgrid# ✓ API connection successful# ✓ Contacts readable# ✓ Lists accessible# ✓ Statistics readable# ✓ Suppressions accessibleแนวทางปฏิบัติที่ดีที่สุด
- ย้าย suppressions ก่อน - ตรวจสอบให้แน่ใจว่า bounces, blocks และ unsubscribes อยู่ใน Brevo ก่อนส่ง
- ใช้ batch contact uploads - PUT สูงสุด 30,000 ผู้ติดต่อต่อคำขอเพื่อประสิทธิภาพ
- ยืนยัน Event Webhook - เปิดใช้งาน signed webhooks พร้อมการตรวจสอบ ECDSA
- แมป custom fields - สร้าง Brevo attributes ที่สอดคล้องกันก่อนการย้ายผู้ติดต่อ
- ซิงค์ข้อมูล engagement - นำเข้าสถิติย้อนหลังสำหรับการแบ่ง segment ใน Brevo
- จัดการ async exports - Contact exports เป็น asynchronous; poll เพื่อรอให้เสร็จสมบูรณ์
ความปลอดภัย
- การยืนยันตัวตนด้วย API Key - Bearer token พร้อมระดับสิทธิ์แบบละเอียด
- Event Webhook signing - การตรวจสอบ ECDSA signature สำหรับ webhook payloads
- การเข้ารหัส TLS - การสื่อสาร API ทั้งหมดเข้ารหัสผ่าน HTTPS
- IP Access Management - จำกัดการเข้าถึง Dashboard และ API ด้วย IP
- การยืนยันตัวตนสองปัจจัย - 2FA สำหรับการเข้าถึงบัญชี