Benachrichtigungsdienst
Über den AFP-Benachrichtigungsdienst können AFP Transparent-Plattformen Benachrichtigungen bei Genehmigungen von PlatformChildSite erhalten, die signalisieren, dass die Website jetzt in der API verfügbar ist.
Um Benachrichtigungen zu erhalten, implementieren Sie einen Server, der POST-Anfragen akzeptiert und die im Schema beschriebene JSON-Nutzlast analysiert (siehe Beispielkonfiguration). Sie müssen dann Ihrem Strategic Partner Manager die Endpunkt-URL mitteilen, damit der Dienst aktiviert werden kann.
Schema
Die Nutzlast der Benachrichtigung muss dem folgenden Schema entsprechen:
{
"$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
}
Weitere notificationTypes
und andere Felder können später hinzugefügt werden.
Beispiele
Eine SITE_APPROVAL
-Benachrichtigung sieht so aus:
{
"platformPublisherId" : "pub-123",
"publisherId" : "pub-456",
"platformChildSiteName" : "accounts/pub-123/platforms/my-platform/childAccounts/pub-456/sites/child-domain.com",
"notificationType": "SITE_APPROVAL"
}
Beispiel für eine Einrichtung
Im folgenden Beispiel wird ein NodeJS-Server verwendet, der den Inhalt einer Benachrichtigung protokolliert:
// 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}`);
});
Beispiel-Endpunkt-URL: https://yourdomain.com/your-endpoint
Prüfen Sie mit curl
, ob der Endpunkt funktioniert. Senden Sie dazu eine POST-Anfrage:
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-Datei konfigurieren
Prüfen Sie, ob dem Benachrichtigungsdienst der Zugriff auf Ihren Endpunkt gewährt wurde. Der Benachrichtigungsdienst berücksichtigt die Anweisungen in der Datei robots.txt
im Stammverzeichnis Ihrer Domain, sofern vorhanden:
User-agent: GoogleOther
Disallow: <ensure your endpoint is not disallowed>