/** * Static test script to verify Setu PAN API is working * This script uses hardcoded values from the curl command * Usage: node scripts/test-setu-api-static.js */ const axios = require('axios'); // Static values from the curl command const SETU_API_URL = 'https://dg-sandbox.setu.co/api/verify/pan'; const CLIENT_ID = '292c6e76-dabf-49c4-8e48-90fba2916673'; const CLIENT_SECRET = '7IZMe9zvoBBuBukLiCP7n4KLwSOy11oP'; const PRODUCT_INSTANCE_ID = '439244ff-114e-41a8-ae74-a783f160622d'; const REQUEST_BODY = { pan: 'ABCDE1234A', consent: 'Y', reason: 'Testing' }; async function testSetuAPI() { console.log('\n๐Ÿงช Testing Setu PAN API with Static Values\n'); console.log('='.repeat(70)); console.log('\n๐Ÿ“‹ Request Details:'); console.log(` URL: ${SETU_API_URL}`); console.log(` Method: POST`); console.log(` Headers:`); console.log(` - Content-Type: application/json`); console.log(` - x-client-id: ${CLIENT_ID}`); console.log(` - x-client-secret: ${CLIENT_SECRET.substring(0, 8)}...`); console.log(` - x-product-instance-id: ${PRODUCT_INSTANCE_ID}`); console.log(` Body:`, JSON.stringify(REQUEST_BODY, null, 2)); console.log('\n๐Ÿš€ Sending request to Setu API...\n'); try { const startTime = Date.now(); const response = await axios.post( SETU_API_URL, REQUEST_BODY, { headers: { 'Content-Type': 'application/json', 'x-client-id': CLIENT_ID, 'x-client-secret': CLIENT_SECRET, 'x-product-instance-id': PRODUCT_INSTANCE_ID }, timeout: 30000 // 30 seconds } ); const endTime = Date.now(); const duration = endTime - startTime; console.log('โœ… SUCCESS! API is working correctly!\n'); console.log('='.repeat(70)); console.log('\n๐Ÿ“Š Response Details:'); console.log(` Status Code: ${response.status} ${response.statusText}`); console.log(` Response Time: ${duration}ms`); console.log(` Response Headers:`, JSON.stringify(response.headers, null, 2)); console.log(`\n๐Ÿ“ฆ Response Body:`); console.log(JSON.stringify(response.data, null, 2)); // Check if response has expected structure if (response.data && response.data.data) { console.log('\nโœ… Response structure is valid!'); if (response.data.data.full_name) { console.log(` PAN Holder Name: ${response.data.data.full_name}`); } if (response.data.message) { console.log(` Message: ${response.data.message}`); } } console.log('\n' + '='.repeat(70)); console.log('\nโœ… Test completed successfully!\n'); } catch (error) { console.log('โŒ ERROR! API request failed!\n'); console.log('='.repeat(70)); if (error.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx console.log('\n๐Ÿ“Š Error Response Details:'); console.log(` Status Code: ${error.response.status} ${error.response.statusText}`); console.log(` Response Headers:`, JSON.stringify(error.response.headers, null, 2)); console.log(`\n๐Ÿ“ฆ Error Response Body:`); console.log(JSON.stringify(error.response.data, null, 2)); console.log('\nโš ๏ธ Possible Issues:'); if (error.response.status === 401) { console.log(' - Invalid credentials (client-id or client-secret)'); } else if (error.response.status === 403) { console.log(' - Access forbidden (check product-instance-id)'); } else if (error.response.status === 400) { console.log(' - Bad request (check PAN format or request body)'); } else if (error.response.status === 404) { console.log(' - Endpoint not found (check API URL)'); } else if (error.response.status >= 500) { console.log(' - Server error (Setu API might be down)'); } } else if (error.request) { // The request was made but no response was received console.log('\nโš ๏ธ No response received from server'); console.log(` Error: ${error.message}`); console.log('\n Possible Issues:'); console.log(' - Network connectivity problem'); console.log(' - API endpoint is unreachable'); console.log(' - Request timeout (took longer than 30 seconds)'); } else { // Something happened in setting up the request that triggered an Error console.log(`\nโš ๏ธ Request setup error: ${error.message}`); } console.log('\n' + '='.repeat(70)); console.log('\nโŒ Test failed!\n'); process.exit(1); } } // Run the test testSetuAPI();