Servizio di notifica
Il servizio di notifica AFP consente alle piattaforme AFP Transparent di ricevere notifiche al momento delle approvazioni di PlatformChildSite, indicando che il sito è ora disponibile nell'API.
Per ricevere notifiche, implementa un server che accetti richieste POST e analizzi il payload JSON descritto nello schema (vedi la configurazione di esempio). Poi devi fornire l'URL dell'endpoint al tuo Strategic Partner Manager per attivare il servizio.
Schema
Il payload della notifica deve rispettare lo schema seguente:
{
"$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
}
Altri campi e notificationTypes
potrebbero essere aggiunti in un secondo momento.
Esempi
Una notifica SITE_APPROVAL
avrà il seguente aspetto:
{
"platformPublisherId" : "pub-123",
"publisherId" : "pub-456",
"platformChildSiteName" : "accounts/pub-123/platforms/my-platform/childAccounts/pub-456/sites/child-domain.com",
"notificationType": "SITE_APPROVAL"
}
Configurazione di esempio
Di seguito è riportato un esempio di server NodeJS che registra i contenuti di una notifica:
// 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 endpoint di esempio: https://yourdomain.com/your-endpoint
Verifica che l'endpoint funzioni inviando una richiesta POST utilizzando 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"}'
Configurare il file robots.txt
Verifica che al servizio di notifica sia consentito l'accesso al tuo endpoint. Il servizio di notifica rispetta le direttive descritte nel file robots.txt
della radice del tuo dominio, se esistente:
User-agent: GoogleOther
Disallow: <ensure your endpoint is not disallowed>