API To Fetch Topics From Community With No Response



Gepostet 17. März 2023

Is there a call that I can make that would let me query something like topics that were created 7 days ago with no replies as of now?


0

2

2 Kommentare

Wow, thanks for the incredibly detailed response! I will give it a try.

0


Hey, Sean!
 
Unfortunately the Topics API does not provide a list of posts made to a given topic. One possible way you could go about this is by pulling a list of posts and filtering those from the last 7 days, then comparing the topic IDs of the posts to a list of topics from your community instance. Here’s a basic example using Javascript in the context of the Zendesk Apps framework:
 
const getTopics = async () => {
// gets date from seven days ago
const sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString().split('T')[0];

// gets community topics
const topicsData = await client.request("/api/v2/community/topics");

// gets posts not older than seven days
const postsData = await client.request(
`/api/v2/help_center/community_posts/search?query=""&created_after=${sevenDaysAgo}`
);

// stores topic IDs
let recentTopics = [];
let topicsWithReplies = [];

// Checks for and stores topics that are equal to or less than seven days old
topicsData.topics.map((topic) => {
const createdAt = new Date(topic.created_at);
if (createdAt >= new Date(sevenDaysAgo)) {
recentTopics.push(topic.id);
}
});

// Checks if posts have been made in topics retrieved above
postsData.results.map((post) => {
if(recentTopics.includes(post.topic_id)){
topicsWithReplies.push(post.topic_id)
}
});

// Print results to console
console.log(topicsWithReplies);
};

getTopics();
 
Feel free to reach out if you have any questions!
 
Tipene

1


Anmelden, um einen Kommentar zu hinterlassen.

Sie finden nicht, wonach Sie suchen?

Neuer Post