/**
* Test Postiz Public API with real API key
*/
import axios from 'axios';
const API_KEY = '0a89feebe1e21582362064558e460b8c0e35eb0133bbf21c2409571bd80eb463';
const BASE_URL = 'https://api.postiz.com/public/v1';
async function testPostizAPI() {
console.log('š Testing Postiz Public API...\n');
console.log(`Base URL: ${BASE_URL}`);
console.log(`API Key: ${API_KEY.substring(0, 20)}...`);
console.log('\n' + '='.repeat(80) + '\n');
const tests = [
{
name: 'Get Integrations (Channels)',
method: 'GET',
endpoint: '/integrations',
},
{
name: 'Get Posts',
method: 'GET',
endpoint: '/posts',
params: {
from: '2025-01-01',
to: '2025-12-31',
},
},
{
name: 'Test Upload endpoint (OPTIONS)',
method: 'OPTIONS',
endpoint: '/upload',
},
];
for (const test of tests) {
console.log(`\nš ${test.name}`);
console.log(` ${test.method} ${test.endpoint}`);
try {
const response = await axios({
method: test.method,
url: `${BASE_URL}${test.endpoint}`,
headers: {
'Authorization': API_KEY,
'Content-Type': 'application/json',
},
params: test.params,
timeout: 15000,
});
console.log(` ā
Success (${response.status})`);
console.log(` Response type: ${typeof response.data}`);
if (Array.isArray(response.data)) {
console.log(` Array length: ${response.data.length}`);
if (response.data.length > 0) {
console.log(` First item:`, JSON.stringify(response.data[0], null, 2).substring(0, 300));
}
} else if (typeof response.data === 'object') {
console.log(` Data:`, JSON.stringify(response.data, null, 2).substring(0, 500));
} else {
console.log(` Data:`, response.data);
}
} catch (error) {
if (error.response) {
console.log(` ā ${error.response.status} - ${error.response.statusText}`);
console.log(` Error:`, JSON.stringify(error.response.data, null, 2).substring(0, 300));
} else if (error.code) {
console.log(` ā ${error.code} - ${error.message}`);
} else {
console.log(` ā ${error.message}`);
}
}
console.log('\n' + '-'.repeat(80));
}
console.log('\n\nš Summary:');
console.log('If you see ā
Success responses, the API key is working!');
console.log('Next step: Update the code to use Postiz Public API endpoints.');
}
testPostizAPI().catch(console.error);