通知服務
AFP 通知服務可讓 AFP Direct 平台在子帳戶和網站狀態變更時接收通知。平台可以使用 Platform API 來調查變更。
如要接收通知,請實作接受 POST 要求的伺服器,並剖析結構定義中所述的 JSON 酬載 (請參閱設定範例)。接著,請將端點網址提供給策略合作夥伴經理,以啟用服務。
結構定義
通知酬載必須符合下列結構定義:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Notification",
"type": "object",
"properties": {
"accountName": {
"type": "string",
"description": "The name of the modified sub-account."
},
"domain": {
"type": "string",
"description": "The domain the notification refers to, if any. Optional (only populated for SITE_APPROVAL)"
},
"notificationType": {
"type": "string",
"enum": ["PUBLISHER_APPROVAL", "SITE_APPROVAL"],
"description": "Type of notification"
}
},
"required": ["platformPublisherId", "publisherId", "notificationType"],
"additionalProperties": false
}
您之後可以新增更多notificationTypes
和其他欄位。
示例
發布商核准通知看起來會像這樣:
{
"accountName" : "platforms/pub-1234567890123456/accounts/pub-0987654321654321",
"notificationType": "PUBLISHER_APPROVAL"
}
網站核准通知看起來會像這樣:
{
"accountName" : "platforms/pub-1234567890123456/accounts/pub-0987654321654321",
"domain": "afpsite.com",
"notificationType": "SITE_APPROVAL"
}
設定範例
以下是記錄通知內容的 NodeJS 伺服器範例:
// Import express
const express = require('express');
// Create an express application
const app = express();
// Middleware to parse JSON bodies
app.use(express.json());
// Define a route to receive POST requests
app.post('/notification', (req, res) => {
console.log('Received account name:', req.body.accountName)
console.log('Received Domain:', req.body.domain)
console.log('Received notification type', req.body.notificationType)
// Send a response back to the client
res.status(200).send('Notification received');
});
// Start the server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
端點網址範例:https://yourdomain.com/your-endpoint
使用 curl
傳送 POST 要求來驗證端點是否正常運作:
curl -X POST https://yourdomain.com/your-endpoint \
-H "Content-Type: application/json" \
-d '{"accountName": "platforms/pub-1234567890123456/accounts/pub-0987654321654321", \
"notificationType": "PUBLISHER_APPROVAL"}'
設定 robots.txt
確保通知服務可存取您的端點。通知服務會採用網域根目錄 robots.txt
檔案中列出的指令 (如有):
User-agent: GoogleOther
Disallow: <ensure your endpoint is not disallowed>