How can I retrieve data from a data extension via API using node JS as the language in SFMC? The documentation only shows sample code using c#, .NET, Java and PHP.
After cloning the repo then running npm install
, the following data extension (MyDataExt
)...
┌─────────────────┬──────┐
│ EmailAddress │ User │
├─────────────────┼──────┤
│ foo@bar.baz │ foo │
└─────────────────┴──────┘
...with the following code in the parent directory...
const ET_Client = require('./lib/ET_Client');
const clientId = '123';
const clientSecret = '456';
const stack = 789;
const client = new ET_Client(clientId, clientSecret, stack);
const deRow = client.dataExtensionRow({
Name: 'MyDataExt',
props: ['EmailAddress', 'User'],
filter: {
leftOperand: 'User',
operator: 'equals',
rightOperand: 'foo'
}
// to return all rows, delete the filter property
});
deRow.get((err, res) => {
if (err) {
console.error(err.message);
} else {
for (const result of res.body.Results) {
for (const property of result.Properties.Property) {
console.log(property);
}
}
}
});
...should output:
{ Name: 'EmailAddress', Value: 'foo@bar.baz' }
{ Name: 'User', Value: 'foo' }