Ich habe die Dokumentation befolgt, aber sie aktualisiert nur den Titel des Themas, ohne den Inhalt zu aktualisieren.
Mein Code (Javascript):
async function updateDiscourseTopic(topic_id) {
const Discourse_API_Key = "Discourse_API_Key";
const url = `https://discourse.mysite.com/t/-/${topic_id}.json`;
const payload = {
title: 'session_1',
raw: "neuer Inhalt (wird nicht angewendet)"
}
const response = await fetch(url, {
method: 'PUT',
headers: {
"Api-Key": Discourse_API_Key,
"Api-Username": "system",
"Content-Type": "application/json",
},
body: JSON.stringify(payload)
});
}
Lilly
( Lilly)
11. Mai 2023 um 13:01
2
Nur eine Vermutung, basierend auf dem Code, aber vielleicht liegt es daran, dass Sie topic_id anstelle von post_id verwenden? Denn der erste Beitrag ist in Discourse mehr oder weniger das Thema?
3 „Gefällt mir“
Canapin
(Coin-coin le Canapin)
11. Mai 2023 um 15:31
3
@Lilly hat Recht.
Ein Thema wird durch Attribute wie Titel, Kategorie, Tags usw. definiert.
Der Inhalt gehört jedoch zu einem Beitrag .
Wenn Sie den Titel und den Inhalt aktualisieren möchten, benötigen Sie 2 Anfragen.
PUT für das Thema
PUT für den ersten Beitrag. Die Beitrags-ID finden Sie im HTML-Code der Seite. Suchen Sie nach dem data-post-id-Attribut in <article>.
Beispiel:
<article id="post_2" aria-label="post #2 by @Lilly" role="region" data-post-id="1288311" data-
topic-id="264640" data-user-id="127856" class="boxed onscreen-post">
3 „Gefällt mir“
Wow, du hast recht, es funktioniert
Und ich habe herausgefunden, wie man die ID des ersten Beitrags in einem Thema über die Discourse API abruft:
async function getFirstPostIdFromOnetopic(topic_id) {
const Discourse_API_Key = "Discourse_API_Key";
const url = `https://discourse.mysite.com/t/${topic_id}/posts.json`;
const response = await fetch(url, {
method: 'GET',
headers: {
"Api-Key": Discourse_API_Key,
"Api-Username": "system",
"Content-Type": "application/json",
}
});
const data = await response.json();
const firstPostId = data.post_stream.posts[0].id;
return firstPostId;
}
Danke dir und @Lilly
3 „Gefällt mir“
system
(system)
Geschlossen,
10. Juni 2023 um 16:12
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.