Ghost API to delete all the Post in one shot

I am trying to delete all the ghost post in the single call and if I hard code post id it works and if i try to do dynamic to delete by passing the post id it fails, any leads?

// Create a token without the client
const jwt = require('jsonwebtoken');
const axios = require('axios');

// Admin API key goes here
const key = 'xxxx';

// Split the key into ID and SECRET
const [id, secret] = key.split(':');

// Create the token (including decoding secret)
const token = jwt.sign({}, Buffer.from(secret, 'hex'), {
    keyid: id,
    algorithm: 'HS256',
    expiresIn: '5m',
    audience: `/admin/`
});
const GhostContentAPI = require('@tryghost/content-api');
const api = new GhostContentAPI({
  url: 'https://play-with-ghost.com/barber-klimax2',
  key: 'xxx',
  version: "v5.0"
});

// fetch 5 posts, including related tags and authors
api.posts
    .browse({limit: 5})
    .then((posts) => {
        posts.forEach((post) => { 
            const url = 'https://play-with-ghost.com/barber-klimax2/ghost/api/admin/posts/'+post.id;
            const headers = { Authorization: `Ghost ${token}` };
            axios.delete(url, { headers })
                .then(response => console.log(response))
                .catch(error => console.error(error));
                    });
                })
    .catch((err) => {
        console.error(err);
    });

response below:

},
response: {
status: 500,
statusText: ‘Internal Server Error’,
headers: {
date: ‘Tue, 31 May 2022 21:03:02 GMT’,
‘content-type’: ‘application/json; charset=utf-8’,
‘content-length’: ‘252’,
connection: ‘close’,
‘cache-control’: ‘no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0’,
etag: ‘W/“fc-MxzIjolbYARl/cQjDO8xTAFHlgU”’,
vary: ‘Accept-Encoding’,
‘x-powered-by’: ‘Express’,
‘cf-cache-status’: ‘DYNAMIC’,
‘expect-ct’: ‘max-age=604800, report-uri=“https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct”’,
‘report-to’: ‘{“endpoints”:[{“url”:“https:\/\/a.nel.cloudflare.com\/report\/v3?s=LD39%2FTHlYMn829yZaNQ6OstOAoqd8MHY0qREidh6RScS0JNLCVnbo9ZIOvmIrczB0DoBNP446EkkcfzEdBRV2UzRfRWUjm9et1OAXLkZ6IWQ0LG8nofQkIBIwunJdJlHLC7tXh8Q”}],“group”:“cf-nel”,“max_age”:604800}’,
nel: ‘{“success_fraction”:0,“report_to”:“cf-nel”,“max_age”:604800}’,
server: ‘cloudflare’,
‘cf-ray’: ‘7142a7678914776e-LHR’,
‘alt-svc’: ‘h3=“:443”; ma=86400, h3-29=“:443”; ma=86400’
},
config: {
transitional: [Object],
adapter: [Function: httpAdapter],
transformRequest: [Array],
transformResponse: [Array],
timeout: 0,
xsrfCookieName: ‘XSRF-TOKEN’,
xsrfHeaderName: ‘X-XSRF-TOKEN’,
maxContentLength: -1,
maxBodyLength: -1,
env: [Object],
validateStatus: [Function: validateStatus],
headers: [Object],
method: ‘delete’,
url: ‘https://play-with-ghost.com/barber-klimax2/ghost/api/admin/posts/5ffbc209971b9b00072d83c6’,
data: undefined

Is there any reason you don’t want to use the Ghost Admin API SDK (rather than the Content API)?

There’s support built-in for deleting posts.