Usługa powiadomień

Usługa powiadomień AFP umożliwia platformom z przejrzystością AFP otrzymywanie powiadomień o zatwierdzeniu PlatformChildSite, co oznacza, że strona jest teraz dostępna w interfejsie API.

Aby otrzymywać powiadomienia, wdrożyć serwer, który akceptuje żądania POST i analizuje ładunek JSON określony w schemacie (patrz przykładowa konfiguracja). Następnie musisz podać URL punktu końcowego swojemu menedżerowi ds. partnera strategicznego, aby aktywować usługę.

Schemat

Ładunek powiadomienia musi być zgodny z tym schematem:

{
  "$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
}

W przyszłości możemy dodać więcej pól notificationTypes i inne.

Przykłady

Powiadomienie SITE_APPROVAL będzie wyglądać tak:

{
  "platformPublisherId" : "pub-123",
  "publisherId" : "pub-456",
  "platformChildSiteName" : "accounts/pub-123/platforms/my-platform/childAccounts/pub-456/sites/child-domain.com",
  "notificationType": "SITE_APPROVAL"
}

Przykładowa konfiguracja

Poniżej znajdziesz przykład serwera NodeJS, który rejestruje zawartość powiadomienia:

// 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}`);
});

Przykładowy adres URL punktu końcowego: https://yourdomain.com/your-endpoint

Aby sprawdzić, czy punkt końcowy działa, wyślij żądanie POST za pomocą 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"}'

Konfigurowanie pliku robots.txt

Sprawdź, czy usługa powiadomień ma dostęp do Twojego punktu końcowego. Usługa powiadomień przestrzega dyrektyw opisanych w pliku robots.txt w katalogu głównym Twojej domeny (jeśli istnieje):

User-agent: GoogleOther
Disallow: <ensure your endpoint is not disallowed>