/**
* Test script to find correct Postiz API endpoints
* Run with: node test-api.js
*/
import axios from 'axios';
import dotenv from 'dotenv';
dotenv.config();
// Test configurations
const configs = [
{
name: 'Config 1: api.postiz.com with full URL as token',
baseURL: 'https://api.postiz.com',
token: process.env.POSTIZ_API_TOKEN,
},
{
name: 'Config 2: api.postiz.com with hash only',
baseURL: 'https://api.postiz.com',
token: process.env.POSTIZ_API_TOKEN?.split('/').pop() || process.env.POSTIZ_API_TOKEN,
},
{
name: 'Config 3: app.postiz.com',
baseURL: 'https://app.postiz.com',
token: process.env.POSTIZ_API_TOKEN,
},
{
name: 'Config 4: postiz.app',
baseURL: 'https://postiz.app',
token: process.env.POSTIZ_API_TOKEN,
},
];
// Possible endpoints to test
const endpoints = [
'/v1/posts',
'/api/v1/posts',
'/posts',
'/api/posts',
'/v1/media',
'/api/v1/media',
'/media',
'/api/media',
'/mcp/posts',
'/mcp/media',
];
async function testEndpoint(config, endpoint) {
try {
const client = axios.create({
baseURL: config.baseURL,
headers: {
'Authorization': `Bearer ${config.token}`,
'Content-Type': 'application/json',
},
timeout: 10000,
});
const response = await client.get(endpoint, {
params: { limit: 1 },
});
return {
success: true,
status: response.status,
data: response.data,
};
} catch (error) {
if (error.response) {
// Server responded with error
return {
success: false,
status: error.response.status,
error: error.response.data?.message || error.response.statusText,
};
} else if (error.code === 'ENOTFOUND') {
return {
success: false,
error: 'DNS not found - URL does not exist',
};
} else {
return {
success: false,
error: error.message,
};
}
}
}
async function main() {
console.log('š Testing Postiz API Configurations...\n');
console.log('Current .env values:');
console.log(` POSTIZ_BASE_URL: ${process.env.POSTIZ_BASE_URL}`);
console.log(` POSTIZ_API_TOKEN: ${process.env.POSTIZ_API_TOKEN?.substring(0, 50)}...`);
console.log('\n' + '='.repeat(80) + '\n');
for (const config of configs) {
console.log(`\nš ${config.name}`);
console.log(` Base URL: ${config.baseURL}`);
console.log(` Token: ${config.token?.substring(0, 30)}...`);
console.log('\n Testing endpoints:');
for (const endpoint of endpoints) {
process.stdout.write(` ${endpoint.padEnd(20)}`);
const result = await testEndpoint(config, endpoint);
if (result.success) {
console.log(`ā
SUCCESS (${result.status})`);
console.log(` Response: ${JSON.stringify(result.data).substring(0, 100)}...`);
} else if (result.status) {
console.log(`ā ${result.status} - ${result.error}`);
} else {
console.log(`ā ${result.error}`);
}
// Small delay to avoid rate limiting
await new Promise(resolve => setTimeout(resolve, 200));
}
console.log('\n' + '-'.repeat(80));
}
console.log('\n\nš Next Steps:');
console.log('1. Find the configuration that shows ā
SUCCESS');
console.log('2. Update your .env file with the correct base URL');
console.log('3. Update src/postizClient.ts with the correct endpoints');
console.log('4. Re-run: npm run build && npm run web');
}
main().catch(console.error);