Steps involved in creating Adobe Campaign Standard profile using AEM Forms Form Data Model

Create Custom Authentication

When creating Data Source with the swagger file, AEM Forms supports the following kinds of authentication types

  • None
  • OAuth 2.0
  • Basic Authentication
  • API Key
  • Custom Authentication

 

CampaignFDM

We will have to use custom authentication to make REST calls to Adobe Campaign Standard.

To use custom authentication, we will have to develop an OSGi component that implements the IAuthentication interface

The method getAuthDetails needs to be implemented. This method will return AuthenticationDetails object. This AuthenticationDetails object will have the required HTTP headers set that is needed to make the REST API call to Adobe Campaign.

The following is the code that was used in creating custom authentication. The method getAuthDetails does all the work. We create AuthenticationDetails object. Then we add the appropriate HttpHeaders to this object and return this object.

 

package aemfd.campaign.core;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.aemfd.dermis.authentication.api.IAuthentication;
import com.adobe.aemfd.dermis.authentication.exception.AuthenticationException;
import com.adobe.aemfd.dermis.authentication.model.AuthenticationDetails;
import com.adobe.aemfd.dermis.authentication.model.Configuration;

import aemforms.campaign.core.CampaignService;
import formsandcampaign.demo.CampaignConfigurationService;
@Component(service=IAuthentication.class,immediate=true)

public class CampaignAuthentication implements IAuthentication {
	@Reference
	CampaignService campaignService;
	 @Reference
	    CampaignConfigurationService config;
private Logger log = LoggerFactory.getLogger(CampaignAuthentication.class);
	@Override
	public AuthenticationDetails getAuthDetails(Configuration arg0) throws AuthenticationException {
	try {
			AuthenticationDetails auth = new AuthenticationDetails();
			auth.addHttpHeader("Cache-Control", "no-cache");
			auth.addHttpHeader("Content-Type", "application/json");
			auth.addHttpHeader("X-Api-Key",config.getApiKey() );
	        auth.addHttpHeader("Authorization", "Bearer "+campaignService.getAccessToken());
	        log.debug("Returning auth");
	        return auth;
			
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidKeySpecException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
	}

	@Override
	public String getAuthenticationType() {
		// TODO Auto-generated method stub
		return "Campaign Custom Authentication";
	}

}

Create Data Source

The first step is to create the swagger file. The swagger file defines the REST API which is going to be used to create a profile in Adobe Campaign Standard. The swagger file defines the input parameters and the output parameters of the REST API.

A data source is created using the swagger file. Please follow the links for creating a Data Source.

Sample swagger file is given to you as part of the asset's related to this article. Make sure you change the host and basePath to match your ACS instance.

We will have to use custom authentication to make REST calls to Adobe Campaign Standard.

To use custom authentication, we will have to develop an OSGi component that implements the IAuthentication interface

The method getAuthDetails needs to be implemented. This method will return AuthenticationDetails object. This AuthenticationDetails object will have the required HTTP headers set that is needed to make the REST API call to Adobe Campaign.

The following is the code that was used in creating custom authentication. The method getAuthDetails does all the work. We create AuthenticationDetails object. Then we add the appropriate HttpHeaders to this object and return this object.

 

Create Form Data Model

Once the data source is created and configured to use custom authentication, Form Data Model is created using the data source created.

Please follow this link to create the Form Data Model.

Test the solution

To test the solution please follow the following steps:

  • Download and unzip the assets related to this article.
  • Deploy the OSGi bundle.
  • Create an Adaptive Form based on the Form Data Model created in the earlier step.
  • Drag and drop the following elements from the data sources tab on to the Adaptive Form
    • Email
    • First Name
    • Last Name
    • Mobile Phone
  • Configure the submit action to "Submit using Form Data Model".
  • Configure the Data Model to submit appropriately.
  • Preview the form. Fill in the fields and submit.
  • Verify profile is created in Adobe Campaign.

 

Download

Download

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy