1

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.

1 Answer 1

3

After cloning the repo then running npm install, the following data extension (MyDataExt)...

┌─────────────────┬──────┐
│ EmailAddress    │ User │
├─────────────────┼──────┤
│ [email protected]     │ 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: '[email protected]' }
{ Name: 'User', Value: 'foo' }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .