Servizio di notifica
Il servizio di notifica AFP consente alle piattaforme AFP Direct di ricevere notifiche in caso di modifiche dello stato dei subaccount e dei siti. Le piattaforme possono utilizzare l'API Platform per esaminare le modifiche.
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": {
"accountName": {
"type": "string",
"description": "The name of the modified sub-account."
},
"domain": {
"type": "string",
"description": "The domain the notification refers to, if any. Optional (only populated for SITE_APPROVAL)"
},
"notificationType": {
"type": "string",
"enum": ["PUBLISHER_APPROVAL", "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 di approvazione del publisher avrà il seguente aspetto:
{
"accountName" : "platforms/pub-1234567890123456/accounts/pub-0987654321654321",
"notificationType": "PUBLISHER_APPROVAL"
}
Una notifica di approvazione del sito sarà simile alla seguente:
{
"accountName" : "platforms/pub-1234567890123456/accounts/pub-0987654321654321",
"domain": "afpsite.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 account name:', req.body.accountName)
console.log('Received Domain:', req.body.domain)
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 '{"accountName": "platforms/pub-1234567890123456/accounts/pub-0987654321654321", \
"notificationType": "PUBLISHER_APPROVAL"}'
Configurare il file robots.txt
Assicurati 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>