通知服務

AFP 通知服務可讓 AFP Transparent 平台在收到 PlatformChildSite 核准通知時,收到通知,表示該網站現在可在 API 中使用。

如要接收通知,請實作可接受 POST 要求的伺服器,並剖析 結構定義中所述的 JSON 酬載 (請參閱設定範例)。接著,您需要將端點網址提供給策略合作夥伴管理員,才能啟用服務。

結構定義

通知酬載必須遵循下列結構定義:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Notification",
  "type": "object",
  "properties": {
    "platformPublisherId": {
      "type": "string",
      "description": "The unique identifier for the platform publisher."
    },
    "publisherId": {
      "type": "string",
      "description": "The unique identifier for the publisher."
    },
    "platformChildSiteName": {
      "type": "string",
      "description": "The name of the PlatformChildSite the notification refers to (populated for SITE_APPROVAL)."
    },
    "notificationType": {
      "type": "string",
      "enum": ["SITE_APPROVAL"],
      "description": "Type of notification"
    },
  },
  "required": ["platformPublisherId", "publisherId", "notificationType"],
  "additionalProperties": false
}

之後可以新增更多 notificationTypes 和其他欄位。

範例

SITE_APPROVAL 通知如下所示:

{
  "platformPublisherId" : "pub-123",
  "publisherId" : "pub-456",
  "platformChildSiteName" : "accounts/pub-123/platforms/my-platform/childAccounts/pub-456/sites/child-domain.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 platformPublisherId:', req.body.platformPublisherId)
    console.log('Received publisherId:', req.body.publisherId)
    console.log('Received platformChildSiteName:', req.body.platformChildSiteName)
    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 '{"platformPublisherId" : "pub-123", \
          "publisherId" : "pub-456", \
          "platformChildSiteName" : "accounts/pub-123/platforms/my-platform/childAccounts/pub-456/sites/child-domain.com", \
          "notificationType": "SITE_APPROVAL"}'

設定 robots.txt

確認通知服務是否有權存取端點。通知服務會遵循網域根目錄 robots.txt 檔案中列出的指令 (如果有的話):

User-agent: GoogleOther
Disallow: <ensure your endpoint is not disallowed>