// Destructuring to get postId from input variables const { wpDomain, wpUsername, wpApikey, wpPostId } = args.inputVars;
// Custom function to encode a string to Base64 function base64Encode(str) { const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; let encoded = '', i = 0;
while (i < str.length) { const a = str.charCodeAt(i++); const b = i < str.length ? str.charCodeAt(i++) : 0; const c = i < str.length ? str.charCodeAt(i++) : 0;
const base64Credentials = base64Encode(`${wpUsername}:${wpApikey}`); const apiUrl = `https://${wpDomain}/wp-json/wp/v2/posts/${wpPostId}`; // Append postId to the URL
// Fetch API data with Basic Authentication to delete the post try { const response = await fetch(apiUrl, { method: 'DELETE', headers: { "Authorization": `Basic ${base64Credentials}` } });