Repository navigation
Expand file tree
/
Copy pathscratch_investigate_po_lines.ts
More file actions
51 lines (42 loc) · 1.9 KB
/
Copy pathscratch_investigate_po_lines.ts
File metadata and controls
51 lines (42 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import axios from 'axios';
import { db } from './src/db';
import { eq } from 'drizzle-orm';
import { systemConfig } from './src/db/schema';
import { decrypt } from './src/lib/crypto';
async function investigatePoLines() {
const config = await db.query.systemConfig.findFirst({
where: eq(systemConfig.key, 'WORKGURU_API_CREDENTIALS'),
});
const { apiKey, apiSecret } = config.value as { apiKey: string; apiSecret: string };
const authRes = await axios.post('https://api.workguru.io/api/ClientTokenAuth/Authenticate/api/client/v1/tokenauth', {
apiKey: decrypt(apiKey),
secret: decrypt(apiSecret)
});
const token = authRes.data.accessToken;
const headers = { Authorization: `Bearer ${token}` };
const poId = '1201071';
console.log(`Fetching PO ${poId} details...`);
try {
const res = await axios.get(`https://api.workguru.io/api/services/app/PurchaseOrder/GetPurchaseOrderById`, {
headers,
params: { id: poId }
});
const detail = res.data.result || res.data;
const allFields = Object.keys(detail);
const arrayFields = allFields.filter(k => Array.isArray(detail[k]));
console.log('\nArray fields found:', arrayFields);
for (const field of arrayFields) {
const val = detail[field];
console.log(`Field "${field}" has ${val.length} items`);
if (val.length > 0) {
console.log(`Sample item from "${field}":`, JSON.stringify(val[0], null, 2));
}
}
console.log('\nPO Status:', detail.status || detail.Status);
console.log('Expected Date:', detail.expectedDate || detail.ExpectedDate);
console.log('Total:', detail.total || detail.Total);
} catch (err: any) {
console.error('Fetch failed:', err.response?.data || err.message);
}
}
investigatePoLines().catch(console.error);