/sfmc-restapi-nodejs

A sample Node.js web app that calls Marketing Cloud REST APIs

Primary LanguageTypeScriptMIT LicenseMIT

What's here?

A demo Node.js web app that calls Marketing Cloud REST APIs

One-time demo setup

1. Add an API Integration component

Add an API Integration component in Marketing Cloud.

See API Integration for more details.

  • Make sure Perform server-to-server requests is checked.
  • Select the Marketing Cloud scope for your API calls

2. Set environment variables

  1. Get the ClientID and ClientSecret from API Integration component and put in the following environment variables on your local computer:
    • SFMC_API_CLIENTID=YOUR_CLIENTID
    • SFMC_API_CLIENTSECRET=YOUR_CLIENTSECRET

See Get an API Key for more details.

Run locally on your computer

The steps below are for MacOS. Modify as needed for your operating system.

Install Node.js

Download and install Node.js for your operating system: https://nodejs.org/en/download/

Get the source code

TIP: If you have Git installed then you can do git clone https://github.com/sanagama/sfmc-restapi-nodejs.git instead.

  1. Browse to https://github.com/sanagama/sfmc-restapi-nodejs
  2. Click Clone or Download then click Download ZIP
  3. Save the ZIP file to your HOME directory as ~/sfmc-restapi-nodejs.zip
  4. Extract the zip file to your HOME directory ~/sfmc-restapi-nodejs.zip

Run the web app

Type the following commands in the Terminal window to run the web app:

cd ~/sfmc-restapi-nodejs
npm install
npm run

Launch your browser and navigate to https://localhost:5000/newcontact

Run in Heroku

If you wish, you can also run this web app in Heroku, AWS, Azure, GCP, etc.

Here are detailed instructions on running Node.js web apps in Heroku: https://devcenter.heroku.com/articles/deploying-nodejs

TIP: Remember to set the following environment variables for the Herkou app:

  • SFMC_API_CLIENTID=YOUR_CLIENTID
  • SFMC_API_CLIENTSECRET=YOUR_CLIENTSECRET

Looking for more info?

Check out these resources to help you get going: