Creating Campaigns in Amazon Pinpoint - Amazon SDK for Java 1.x
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

We announced the upcoming end-of-support for Amazon SDK for Java (v1). We recommend that you migrate to Amazon SDK for Java v2. For dates, additional details, and information on how to migrate, please refer to the linked announcement.

Creating Campaigns in Amazon Pinpoint

You can use campaigns to help increase engagement between your app and your users. You can create a campaign to reach out to a particular segment of your users with tailored messages or special promotions. This example demonstrates how to create a new standard campaign that sends a custom push notification to a specified segment.

Create a Campaign

Before creating a new campaign, you must define a Schedule and a Message and set these values in a WriteCampaignRequest object.

Imports

import com.amazonaws.services.pinpoint.AmazonPinpoint; import com.amazonaws.services.pinpoint.AmazonPinpointClientBuilder; import com.amazonaws.services.pinpoint.model.CreateCampaignRequest; import com.amazonaws.services.pinpoint.model.CreateCampaignResult; import com.amazonaws.services.pinpoint.model.Action; import com.amazonaws.services.pinpoint.model.CampaignResponse; import com.amazonaws.services.pinpoint.model.Message; import com.amazonaws.services.pinpoint.model.MessageConfiguration; import com.amazonaws.services.pinpoint.model.Schedule; import com.amazonaws.services.pinpoint.model.WriteCampaignRequest;

Code

Schedule schedule = new Schedule() .withStartTime("IMMEDIATE"); Message defaultMessage = new Message() .withAction(Action.OPEN_APP) .withBody("My message body.") .withTitle("My message title."); MessageConfiguration messageConfiguration = new MessageConfiguration() .withDefaultMessage(defaultMessage); WriteCampaignRequest request = new WriteCampaignRequest() .withDescription("My description.") .withSchedule(schedule) .withSegmentId(segmentId) .withName("MyCampaign") .withMessageConfiguration(messageConfiguration);

Then create a new campaign in Amazon Pinpoint by providing the WriteCampaignRequest with the campaign configuration to a CreateCampaignRequest object. Finally, pass the CreateCampaignRequest object to the AmazonPinpointClient’s createCampaign method.

Code

CreateCampaignRequest createCampaignRequest = new CreateCampaignRequest() .withApplicationId(appId).withWriteCampaignRequest(request); CreateCampaignResult result = client.createCampaign(createCampaignRequest);

See the complete example on GitHub.

More Information