3. Connect to Adobe Campaign Standard from Runtime

In this section, we’ll step through the process of setting up Analytics, connect your Analytics instance with AEM, use Analytics to configure your first Trigger, and get your first Trigger to fire.

Add Campaign to your Integration

Generate a JWT Token and Access Token

Familiarize with Campaign Standard API

With the Adobe Campaign Standard API, you get access to the following functionalities:

Adobe Campaign APIs must be used Server to Server only.

Before diving into code, let’s use the Postman to play with this API

Set up the API

Standard calls with Profile

There are four default calls related to Profile in that collection. Play with them to see if you can add your own Profile and update it!



Explore #3

If you’ve tried these four, tweak the call to see what else you can do with profile and data via the Campaign Standard API. Refer to Campaign Standard API Documentation for some idea!



Transactional Message

These two calls related to Transactional message are defaulted to a Transactional Event I’ve set up in Campaign Standard. In Transactional M - Trigger a message, modify the body of the call to use your email, and see what the sample email looks like in your inbox!


Add Campaign Standard to your Console Integration

Then, let’s switch over so that you are using your own Campaign API integration in this demo.


Using an API in Runtime

In this section Campaign Standard as an example to show how you can currenty work with an Adobe API in Runtime.

Authentication

Any API that accesses a service or content on behalf of an end user authenticates using the OAuth and JSON Web Token standards. For service-to-service integrations, you will also need a JSON Web Token (JWT) that encapsulates your client credentials and authenticates the identity of your integration. You exchange the JWT for the OAuth token that authorizes access.

For more details, please refer to Service Account Integration documentation

The JWT Workflow contains 6 steps

We have completed 1-4 in previous steps, we’ll focus on step 5 and 6 in the next section.

5- Create your JSON Web Token (JWT) Use your client credentials generated for your integration to create a JWT, and sign it with your private key. The JWT encodes all of the identity and security information that Adobe needs to verify your identity and grant you access to Adobe services and events.

Several public libraries are available for creating a JWT. The JWT must be digitally signed and base-64 encoded for inclusion in the access request.

6- Exchange your JWT for an Access Token

To initiate an API session, you use the JWT to obtain an access token from Adobe, by making a POST request to Adobe’s Identity Management Service (IMS).

Send a POST request to:

https://ims-na1.adobelogin.com/ims/exchange/jwt/

The body of the request should contain URL-encoded parameters with your Client ID (API Key), Client Secret, and JWT:

client_id={api_key_value}&client_secret={client_secret_value}&jwt_token={base64_encoded_JWT}

Sample Request

curl -X POST \
  https://ims-na1.adobelogin.com/ims/exchange/v1/jwt \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d 'jwt_token={encoded-jwt}&client_id={client-id}&client_secret={client-secret}'

Sample Response

{
  "token_type": "bearer",
  "access_token": "{encoded-token}",
  "expires_in": 86399981
}

Now that we’ve walked through the high level task, let’s dig in to see 1) how you can use I/O Console as a helper in this process and 2) how you can do it programatically.

a - Console as helper

The Console has built-in functionality to help you generate a signed and encoded JWT, and provides a customized curl command that helps you exchange for the access token.

b - Programatically

Let’s try to build this in Runtime as well. Navigate to the campaign-sample code that you’ve downloaded.

As an alternative to writing all your action code in a single JavaScript source file, you can write an action as a npm package. We are going to try it in this section.

Understand the code



Challenge # 3

Make sure you understand the code and what’s happening here. Follow the following instructions to get your access token! Your function should be able to print out the access token in the Console when done.



Challenge # 4

Using the access token printed from Console. Writ a simple zipped action that make a GET call to retrieve profiles.

Here’s a short sample code in Request to help you get started. Don’t forget to include the dependencies!

var accessToken, clientID, tenant;

var options = { 
    method: 'GET',
    url: 'https://mc.adobe.io/' + tenant +'/target/activities',
    headers: {
        'cache-control': 'no-cache',
        'content-type': 'application/vnd.adobe.target.v1+json',
        'x-api-key': clientID,
        authorization: accessToken 
    }
};

request(options, function (error, response, body) {
    if (error) throw new Error(error);

    console.log("Get Activity Result: " + body);
    resolve({body: body});
});


Challenge # 5

Time to combine challenge 3 with challenge 4 to make a single action in Runtime that 1) generates the JWT 2) exchanges it for access token 3) makes a GET call to retrieve profiles from Campaign.

Be careful with the Promises – given the actions are asynchrous, the order could get tricky.



**Back: ** Chapter 2 - Receive your Trigger in a Runtime action **Next: ** Chapter 4 - Orchestrate Trigger to Campaign in Runtime