import { config } from 'dotenv';
import { resolve } from 'path';
config({ path: resolve('/opt/stacks/pulse/.env.local') });

async function main() {
  const res = await fetch(`${process.env.AUTOTASK_API_URL}/Tickets/query`, {
    method: 'POST',
    headers: {
      Username: process.env.AUTOTASK_USERNAME!,
      Secret: process.env.AUTOTASK_SECRET!,
      APIIntegrationcode: process.env.AUTOTASK_API_INTEGRATION_CODE!,
      'Content-Type': 'application/json',
      Accept: 'application/json',
    },
    body: JSON.stringify({ MaxRecords: 1, filter: [{ field: 'id', op: 'gt', value: 0 }] }),
  });
  const data = await res.json();
  const rec = data.items[0];
  console.log('All string fields:');
  for (const [k, v] of Object.entries(rec).sort()) {
    if (typeof v === 'string') console.log(`  ${k.padEnd(45)} len=${(v as string).length}`);
  }
  console.log('\nAll field names (for reference):');
  console.log(Object.keys(rec).sort().join(', '));
}
main().catch(console.error);
