Служба уведомлений
Служба уведомлений AFP позволяет платформам AFP Transparent получать уведомления об одобрении 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
Проверьте работу вашей конечной точки, отправив запрос POST с помощью curl
:
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>