Integrations
Payload CMS Integration
Connect your Payload CMS content to Reaktly.
Overview
If you're using Payload CMS, you can push your content to Reaktly using afterChange hooks or a sync script.
Using Payload Hooks
Add an afterChange hook to your collections to push content on every publish:
import type { CollectionAfterChangeHook } from 'payload';
import crypto from 'crypto';
const REAKTLY_API = process.env.REAKTLY_API_URL;
const API_KEY = process.env.REAKTLY_API_KEY;
const INTEGRATION_ID = process.env.REAKTLY_INTEGRATION_ID;
const KB_ID = process.env.REAKTLY_KB_ID;
export const syncToReaktly: CollectionAfterChangeHook = async ({ doc, collection }) => {
if (doc._status === 'draft') return doc;
const content = typeof doc.content === 'string'
? doc.content
: JSON.stringify(doc.content);
try {
await fetch(`${REAKTLY_API}/ingest`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': API_KEY,
},
body: JSON.stringify({
integrationId: INTEGRATION_ID,
knowledgeBaseId: KB_ID,
sourceType: 'ARTICLE',
externalId: `payload-${collection.slug}-${doc.id}`,
data: {
title: doc.title,
content,
url: `https://your-site.com/${collection.slug}/${doc.slug}`,
hash: crypto.createHash('sha256').update(content).digest('hex'),
},
}),
});
} catch (error) {
console.error('Failed to sync to Reaktly:', error);
}
return doc;
};Full Sync Script
For initial data import, run a one-time sync using Payload's Local API. See our Custom Connector guide for the full pattern.