通知サービス
AFP 通知サービスを使用すると、AFP 透明性プラットフォームは PlatformChildSite の承認時に通知を受け取ることができます。これは、API でサイトが利用可能になったことを示します。
通知を受け取るには、POST リクエストを受け入れて、スキーマに概要が記載されている JSON ペイロードを解析するサーバーを作成します(設定例をご覧ください)。その後、戦略的パートナー マネージャーにエンドポイント URL を提供して、サービスを有効にする必要があります。
スキーマ
通知ペイロードは次のスキーマに準拠する必要があります。
{
"$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}`);
});
エンドポイント URL の例: 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>