0

I'm trying to test SFMC's Node SDK locally, but when i run the index.js file, it returns "No access token" in the CLI. I have my index.js file set up as follows;

const ET_Client     = require('sfmc-fuelsdk-node');
const clientId      = "clientId"
const clientSecret  = "clientSecret"
const stack         = 'S7'
origin              = 'https://endpoint.rest.marketingcloudapis.com/'
authOrigin          = 'https://endpoint.auth.marketingcloudapis.com/'
soapOrigin          = 'https://endpoint.soap.marketingcloudapis.com/'

const client = new ET_Client(clientId, clientSecret, stack, {origin, authOrigin, soapOrigin});

Can anyone tell me what i'm missing?

1 Answer 1

1

So I believe my issue was two-fold...

  1. I believe it's now necessary to use oAuth 2.0 authentication, therefore the following method of retrieving the access token needs to be used
const client = new ET_Client(clientId, clientSecret, stack, {origin, authOrigin, soapOrigin, 
authOptions = { authVersion = 2, accountId = <<TARGET_BUSINESS_UNIT>>, scope = <<DATA_ACCESS_PERMISSIONS>>, applicationType = <<public||web||server>>, redirectURI = <<REDIRECT_URL_FOR_PUBLIC/WEB_APP, authorizationCode = <<AUTH_CODE_FOR_PUBLIC/WEB_APP>>}
}); 
  1. The code above - pulled from the node sdk github page - is actually wrong and returns the following error "SyntaxError: Invalid shorthand property initializer". To fix this, I had to modify the way the objects are initialized within the authOptions obj. The following code worked (notice how properties within the object are defined using ':' instead of '=') ;
const ET_Client     = require('sfmc-fuelsdk-node');
const clientId      = "clientId"
const clientSecret  = "clientSecret"
const stack         = 'S7'


const origin              = 'https://endpoint.rest.marketingcloudapis.com/'
const authOrigin          = 'https://endpoint.auth.marketingcloudapis.com/'
const soapOrigin          = 'https://endpoint.soap.marketingcloudapis.com/'


const client = new ET_Client(
  clientId, 
  clientSecret, 
  stack, 
  {
    origin, 
    authOrigin, 
    soapOrigin, 
    authOptions: { 
      authVersion: 2, 
      accountId: MID, 
      scope: 'data_extensions_read data_extensions_write',
      applicationType: 'server'
    }
  }
); 

You must log in to answer this question.

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