curl ile başlayan, herhangi bir dile taşınabilir bir workflow. Onaylı taslakları periyodik olarak çekin, kendi editorial iş akışınıza besleyin.
Aşağıdaki senaryoda; sunucunuzda dakikada bir çalışan bir cron job vardır, son 5 dakikada
onaylanmış (status=approved) taslakları çeker, kendi CMS'inizin draft koleksiyonuna yazar.
# Interaktif; sonucu bir yere kaydedin
curl -sS -X POST https://newsmachine.umutozan.dev/api/v1/tokens \
-H 'Content-Type: application/json' \
-d '{"email":"[email protected]","password":"***","name":"cms-sync"}'curl -sS "https://newsmachine.umutozan.dev/api/v1/articles?status=approved&per_page=50&from=$(date -u -v-5M '+%Y-%m-%dT%H:%M:%SZ')" \
-H "Authorization: Bearer $TOKEN" \
-H 'Accept: application/json' | jq
Response içinde headline, spot, body, hero_image_url,
tags, category, source_urls alanları bulunur. Bunları
kendi CMS API'nize dönüştürün. Örnek Node script:
import fetch from 'node-fetch';
const AJANS = 'https://newsmachine.umutozan.dev/api/v1';
const CMS = 'https://my-cms.example.com/api';
async function sync() {
const since = new Date(Date.now() - 5*60*1000).toISOString();
const res = await fetch(`${AJANS}/articles?status=approved&per_page=50&from=${since}`, {
headers: { Authorization: `Bearer ${process.env.AJANS_TOKEN}` }
});
const { data } = await res.json();
for (const a of data) {
await fetch(`${CMS}/drafts`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${process.env.CMS_TOKEN}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
externalId: `ajans11-${a.id}`,
title: a.headline,
excerpt: a.spot,
html: a.body,
heroImage: a.hero_image_url,
tags: a.tags,
category: a.category,
sources: a.source_urls,
})
});
}
}
sync().catch(console.error);ajans11-{id} gibi bir external key ile
upsert yapmayı unutmayın. Aksi halde aynı yazı her çekilişte tekrar oluşur.
GET /articles parametreleri:
status — draft, needs_review, approved, published, rejectedcategory — slug: gundem, ekonomi, spor, teknoloji, …from / to — ISO tarih (generated_at aralığı)q — başlıkta LIKE aramapage / per_page — sayfalama (max per_page=100)page'i döndürerek okuyun.source_urls dizisini yazının altında listeleyebilirsiniz.Cron'la sık çekme yerine sunucunuz canlıysa webhook ile push almak daha verimlidir. Detaylar için ana geliştirici sayfası.