최근 검색


최근 검색 없음

Delete 2000 posts with the same subject (description)



2021년 9월 17일에 게시됨

Due some testing, we had the unexpected effect of generating about 2000 tickets with the same subject line.

Based on a recent call with ZD Support, I learned that I can operate on the ticket DB using Chrome DevTools JS console.  Cool!

Question: it is possible to write a script that would 1) search for a ticket by description 2) delete that ticket, 3) iterate until all those tickets were gone.

Please note, I'm not asking for the script itself (although that would be welcome), I would just like to know if that's likely to be possible.  If it's possible, I think I can figure out how to do it.

 


0

2

댓글 2개

image avatar

Zach Anthony

Zendesk Product Manager

Hi Jim,

This is definitely possible using our REST API. To do this I would start by using the Export Search Results API to search for the ticket IDs to be deleted based on the ticket subject.

Here's an example of what that might look like in Javascript:
const SUBDOMAIN = "YOUR SUBDOMAIN";
const TICKET_SUBJECT = "YOUR TICKET SUBJECT";

const retrieveCursorPaginatedResults = async (url) => {
const data = await fetch(url).then((response) => response.json());
let results = data.results;
if (data.meta.has_more) {
results = results.concat(
await retrieveCursorPaginatedResults(data.links.next)
);
}
return results;
};

const retrieveTicketIdsBySubject = async (subdomain, subject) => {
const results = await retrieveCursorPaginatedResults(
`https://${subdomain}.zendesk.com/api/v2/search/export?query=subject:"${subject}"&filter[type]=ticket&page[size]=1000`
);
const ticketIds = results.map((result) => result.id);
return ticketIds;
};

retrieveTicketIdsBySubject(SUBDOMAIN, TICKET_SUBJECT).then((tickets) => {
console.log(tickets);
});
 
You can then leverage the Bulk Delete Tickets API to delete those tickets to delete the tickets in batches of 100 in the background.
 
You could use a function like this to delete the tickets with the ticket IDs you have exported from the search:
const deleteTickets = async (subdomain, ticketIds) => {
while (ticketIds.length > 0) {
const batch = ticketIds.splice(0, 100).toString();
console.log(`Tickets to be deleted: ${batch}`);
const url = `https://${subdomain}.zendesk.com/api/v2/tickets/destroy_many?ids=${batch}`;
const jobStatus = await fetch(url, { method:"DELETE" }).then((response) =>
response.json()
);
console.log(jobStatus);
}
};

 

Hope this helps!

0


Thanks!  With that and other sources I was able to implement the functionality in MS Access, where I could also add other controls. Worked great!

0


댓글을 남기려면 로그인하세요.

원하는 정보를 못 찾으셨나요?

새 게시물