In this blog post, we go through the steps required to get you started with the SAP Marketing Cloud SDK. This involves the following steps:
- Generate a project using Maven Archetype
- Build and deploy your application on Kyma or SAP Cloud Platform – Cloud Foundry (SCP-CF)
Step 1: Infrastructure Setup
Depending on the operating system you use, install the required software as described below:
Execute the following steps in a terminal as administrator.
- Install Homebrew (Mac Packetmanager to help with the remaining installation)
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Install Java Development Kit, if not yet available
brew update brew cask install java
Tip: Install a specific JDK if you like with (e.g., JDK 8)
brew cask install caskroom/versions/java8
- Install Maven
brew update brew install maven
Execute the following steps in a command line window as administrator.
- Install Chocolatey (a package manager for Windows)
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
For more information on Chocolatey and how to use it, visit the following page.
- Install Java Development Kit, if not yet availableInstall a specific JDK (e.g., JDK 8)
choco install jdk8
- Install Maven
choco install maven
To develop your first “Hello World” application with SAP Marketing Cloud SDK, you can work with the IDE of your choice. We recommend that you use Intellij IDEA Ultimate Edition or Eclipse with Spring Tools Suite installed.
Step 2: Create your first HelloWorld application
The following steps explain how to generate your first HelloWorld example using the SAP Marketing Cloud SDK.
Once you have installed Maven, you can use it to quickly generate a project from SAP Marketing Cloud SDK using one of the following Maven Archetype:
- Kyma (com.sap.cloud.mkt:mkt-kyma-spring)
- SAP Cloud Platform Cloud Foundry(SCP-CF) (com.sap.cloud.mkt:ymkt-cf-spring)
Both the archetypes generate a Spring Boot application, powered with SAP Marketing Cloud SDK. The fundamental difference in these archetypes is the underlying platform dependencies.
Create a project using Kyma archetype
If you want to deploy your application on a Kyma cluster, generate your starter project using the below maven archetype:
mvn archetype:generate -DarchetypeGroupId=com.sap.cloud.mkt -DarchetypeArtifactId=mkt-kyma-spring -DarchetypeVersion=1.0.0
While generating a project in interactive mode, enter the following details:
- groupId: GroupID of the maven project being generated
- artifactId: ArtifactID of the maven project being generated
- version: Enter version
- dockerImageName: Docker image tag you want to give once the generated application is pushed to Docker Hub. (format: user/imagetag)
For example, if your docker user name is john and you want to give the name demoapp, then the dockerImageName would be john/demoapp)
- hostName: Access URL on Kyma cluster. This is a public URL to access any Kubernetes service. For example, if your Kyma installation is on a local system, the URL format is demoapp.kyma.local . If you’re deploying on a Kyma cluster, then the format is demoapp.playground.cluster.kyma.cx
Create a project using Cloud Foundry archetype
If you want to deploy your application on SCP Cloud Foundry, generate your starter project using the below maven archetype:
mvn archetype:generate -DarchetypeGroupId=com.sap.cloud.mkt -DarchetypeArtifactId=ymkt-cf-spring -DarchetypeVersion=1.0.0
Once a project is generated, you can import this project to eclipse/IntelliJ with Spring Tool Suite plugin and run the application as Spring Boot application.
Step 3: Consume Marketing OData APIs
In the SDK all the SAP Marketing Cloud APIs are exposed as Virtual Data Models (VDMs) which makes their consumption easy. Also, with VDMs you have the liberty to represent any OData service in an Objected Oriented paradigm. For example, if you want to read a campaign from SAP Marketing Cloud via the SDK, you should use the following code snippet:
List<Campaign> campaigns = new DefaultMktCampaignSrvService().getAllCampaign() .top(20) .skip(0) .filter(Campaign.CAMPAIGN_OWNER_NAME.eq("John Doe")) .select(Campaign.CAMPAIGN_DESCRIPTION, Campaign.CAMPAIGN_EXECUTION_STATUS_NAME, Campaign.CAMPAIGN_NAME) .execute();
Step 4: Build and Deploy Application
Depending on the archetype you have used to generate your project, follow the steps below:
If you have generated your application using Kyma archetype, SDK provides you a bash script which will help you in building and deploying your application to a Kyma cluster. Before running the script, ensure you perform the following steps:
- Install Docker CLI
- Install Kyma and ensure your kubectl (Kubernetes CLI) context is set to point at your Kyma installation
- Add Remote Environment pointing to SAP Marketing Cloud using Kyma’s Application Connector component and ensure a service instance of bound Remote Environment is available to your Kyma’s environment.
You can now build your application using a simple command:
chmod +x build.sh && ./build.sh
Once deployed, you can access the application on the API hostname URL configured during project generation. This URL can be viewed or changed in the generated YAML specification “deployment.yaml”
SAP Cloud Platform – Cloud Foundry
Before you deploy your application on SCP-CF, please ensure you’ve gone through this blog on Calling an Odata Service using S/4HANA Cloud SDK.
To deploy your application on SCP-CF, refer to the blog, on SAP S/4HANA Cloud SDK.
The security model in Kyma uses the service mesh component to enforce authorization through Kubernetes Role Based Authentication (RBAC) in the cluster. The identity federation is managed through Dex, which is an open-source, openID connect identity provider. Dex implements a system of connectors that allow you to delegate authentication to external OpenID Connect and SAML2-compliant identity providers and use their user stores. For further details on authorization and authentication, please refer to Kyma documentation.