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
- Get the
ClientID
andClientSecret
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 dogit clone https://github.com/sanagama/sfmc-restapi-nodejs.git
instead.
- Browse to https://github.com/sanagama/sfmc-restapi-nodejs
- Click
Clone or Download
then clickDownload ZIP
- Save the ZIP file to your
HOME
directory as~/sfmc-restapi-nodejs.zip
- 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
https://localhost:5000/newcontact
Launch your browser and navigate toRun 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:
- Marketing Cloud Developer Center: https://developer.salesforce.com/devcenter/marketing-cloud
- Create an Installed Package: https://sforce.co/InstalledPackage
- Marketing Cloud APIs: https://sforce.co/CloudAPI
- Marketing Cloud SDKs: https://sforce.co/SDK
- Content Block SDK: https://github.com/salesforce-marketingcloud/blocksdk
- Content Builder SDK: https://sforce.co/ContentBuilder
- MobilePush and Journey Builder SDKs: https://sforce.co/MobilePushSDK