SendGrid Connector

เชื่อมต่อบัญชี SendGrid ของคุณกับ Brevo ผ่าน Tajo เพื่อการย้ายโครงสร้างพื้นฐานอีเมล การซิงค์ผู้ติดต่อ การโอนข้อมูลแคมเปญ และ engagement analytics ที่รวมกันบนทั้งสองแพลตฟอร์ม

ภาพรวม

คุณสมบัติค่า
แพลตฟอร์มSendGrid (Twilio)
หมวดหมู่การตลาด
ความซับซ้อนในการตั้งค่าง่าย
การผสานรวมอย่างเป็นทางการใช่
ข้อมูลที่ซิงค์ผู้ติดต่อ แคมเปญ Transactional Email เหตุการณ์
API Base URLhttps://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

ข้อกำหนดเบื้องต้น

ก่อนเริ่มต้น ตรวจสอบให้แน่ใจว่าคุณมี:

  1. บัญชี SendGrid (Free, Essentials, Pro หรือ Premier)
  2. SendGrid API key ที่มีสิทธิ์ที่จำเป็น
  3. บัญชี Brevo ที่มีสิทธิ์เข้าถึง API
  4. บัญชี Tajo

การยืนยันตัวตน

การยืนยันตัวตนด้วย API Key

SendGrid ใช้การยืนยันตัวตนด้วย bearer token

Terminal window
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 Access
Suppressions: Read Access
Tracking: 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_TYPE

API 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กรณีการใช้งาน
processedSendGrid รับอีเมลแล้วการยืนยันการส่ง
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 SendGrid
await tajo.connectors.connect('sendgrid', {
apiKey: process.env.SENDGRID_API_KEY
});

ย้ายผู้ติดต่อไปยัง Brevo

// Full contact migration from SendGrid to Brevo
await tajo.connectors.sync('sendgrid', {
type: 'full',
resources: ['contacts', 'suppressions'],
options: {
includeCustomFields: true,
migrateListMemberships: true,
migrateSuppressions: true
}
});
// Check migration status
const 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 Webhook
app.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 PUT3 คำขอ/วินาทีBatch สูงสุด 30,000 ผู้ติดต่อ
Marketing Contacts Search50 คำขอ/วินาทีต่อ API key
General API1,000 คำขอ/วินาทีต่อ API key
Event WebhookBatch deliveryสูงสุด 1,000 เหตุการณ์ต่อ POST

ขีดจำกัด Mail Send

ขีดจำกัด Mail Send ขึ้นอยู่กับแผน SendGrid ของคุณ บัญชีฟรีถูกจำกัดที่ 100 อีเมล/วัน ตรวจสอบรายละเอียดแผนของคุณสำหรับขีดจำกัดการส่งที่แน่นอน

การแก้ไขปัญหา

ปัญหาทั่วไป

ปัญหาสาเหตุวิธีแก้
401 UnauthorizedAPI key ไม่ถูกต้องตรวจสอบ API key ใน SendGrid Settings
403 Forbiddenสิทธิ์ API key ไม่เพียงพอสร้าง key ใหม่พร้อม scopes ที่จำเป็น
Contact export pendingกำลังประมวลผลชุดข้อมูลขนาดใหญ่Poll export status endpoint จนกว่าจะเสร็จสมบูรณ์
Suppression sync ไม่สมบูรณ์ต้องใช้ paginationใช้ pagination พร้อมพารามิเตอร์ offset
ไม่ได้รับ Event webhookURL ไม่ได้รับการยืนยันทำการยืนยัน webhook URL ให้สมบูรณ์ใน SendGrid

โหมด Debug

เปิดใช้งาน verbose logging:

connectors:
sendgrid:
debug: true
log_level: verbose
log_webhooks: true

ทดสอบการเชื่อมต่อ

Terminal window
tajo connectors test sendgrid
# ✓ API connection successful
# ✓ Contacts readable
# ✓ Lists accessible
# ✓ Statistics readable
# ✓ Suppressions accessible

แนวทางปฏิบัติที่ดีที่สุด

  1. ย้าย suppressions ก่อน - ตรวจสอบให้แน่ใจว่า bounces, blocks และ unsubscribes อยู่ใน Brevo ก่อนส่ง
  2. ใช้ batch contact uploads - PUT สูงสุด 30,000 ผู้ติดต่อต่อคำขอเพื่อประสิทธิภาพ
  3. ยืนยัน Event Webhook - เปิดใช้งาน signed webhooks พร้อมการตรวจสอบ ECDSA
  4. แมป custom fields - สร้าง Brevo attributes ที่สอดคล้องกันก่อนการย้ายผู้ติดต่อ
  5. ซิงค์ข้อมูล engagement - นำเข้าสถิติย้อนหลังสำหรับการแบ่ง segment ใน Brevo
  6. จัดการ 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 สำหรับการเข้าถึงบัญชี

แหล่งข้อมูลที่เกี่ยวข้อง

Subscribe to updates

developer-docs

Drop your email or phone number — we'll send you what matters next.

auto-detect
ผู้ช่วย AI

สวัสดี! ถามฉันเกี่ยวกับเอกสารได้เลย