-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-soap.js
More file actions
126 lines (106 loc) · 4.18 KB
/
debug-soap.js
File metadata and controls
126 lines (106 loc) · 4.18 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* Debug script to test SOAP connectivity
*/
import axios from 'axios';
import dotenv from 'dotenv';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
dotenv.config({ path: path.resolve(__dirname, '.env') });
async function debug() {
console.log('=== SFMC SOAP Debug ===\n');
// 1. Show config
console.log('Configuration:');
console.log(' AUTH_URL:', process.env.SFMC_AUTH_URL);
console.log(' SOAP_URL:', process.env.SFMC_SOAP_URL);
console.log(' ACCOUNT_ID:', process.env.SFMC_ACCOUNT_ID);
console.log('');
// 2. Get token
console.log('Fetching OAuth token...');
const tokenUrl = `${process.env.SFMC_AUTH_URL}/v2/token`;
console.log(' Token URL:', tokenUrl);
try {
const tokenResponse = await axios.post(tokenUrl, {
grant_type: 'client_credentials',
client_id: process.env.SFMC_CLIENT_ID,
client_secret: process.env.SFMC_CLIENT_SECRET,
account_id: process.env.SFMC_ACCOUNT_ID
}, {
headers: { 'Content-Type': 'application/json' }
});
console.log('\nToken Response:');
console.log(' access_token:', tokenResponse.data.access_token ? '[RECEIVED]' : '[MISSING]');
console.log(' rest_instance_url:', tokenResponse.data.rest_instance_url);
console.log(' soap_instance_url:', tokenResponse.data.soap_instance_url);
console.log('');
const accessToken = tokenResponse.data.access_token;
// Determine SOAP URL to use
let soapUrl = tokenResponse.data.soap_instance_url || process.env.SFMC_SOAP_URL;
// Ensure it ends with /Service.asmx
if (!soapUrl.endsWith('/Service.asmx')) {
if (soapUrl.endsWith('/')) {
soapUrl = soapUrl + 'Service.asmx';
} else {
soapUrl = soapUrl + '/Service.asmx';
}
}
console.log('Using SOAP URL:', soapUrl);
// 3. Test SOAP request
console.log('\nTesting SOAP Retrieve...');
const soapEnvelope = `<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:et="http://exacttarget.com/wsdl/partnerAPI">
<soapenv:Header>
<fueloauth xmlns="http://exacttarget.com">${accessToken}</fueloauth>
</soapenv:Header>
<soapenv:Body>
<RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
<RetrieveRequest>
<ObjectType>DataFolder</ObjectType>
<Properties>ID</Properties>
<Properties>Name</Properties>
<Properties>ContentType</Properties>
<Filter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="SimpleFilterPart">
<Property>ContentType</Property>
<SimpleOperator>equals</SimpleOperator>
<Value>dataextension</Value>
</Filter>
</RetrieveRequest>
</RetrieveRequestMsg>
</soapenv:Body>
</soapenv:Envelope>`;
console.log(' Sending POST to:', soapUrl);
const soapResponse = await axios.post(soapUrl, soapEnvelope, {
headers: {
'Content-Type': 'text/xml; charset=utf-8',
'SOAPAction': 'Retrieve'
},
timeout: 30000
});
console.log('\nSOAP Response Status:', soapResponse.status);
console.log('Response preview:', soapResponse.data.substring(0, 1500));
// Check if response contains error
if (soapResponse.data.includes('OverallStatus>Error')) {
console.log('\n⚠️ Response contains error status');
// Extract error details
const match = soapResponse.data.match(/<OverallStatusMessage>([^<]+)<\/OverallStatusMessage>/);
if (match) {
console.log('Error message:', match[1]);
}
} else {
console.log('\n✓ SOAP connection successful!');
}
} catch (error) {
console.log('\n❌ Error occurred:');
if (error.response) {
console.log(' HTTP Status:', error.response.status, error.response.statusText);
console.log(' Response Headers:', JSON.stringify(error.response.headers, null, 2));
console.log(' Response Data:', typeof error.response.data === 'string'
? error.response.data.substring(0, 1000)
: JSON.stringify(error.response.data, null, 2));
} else {
console.log(' Error:', error.message);
}
}
}
debug();