The AWS SDK for Java 1.x reached end-of-support on December 31, 2025. We recommend that you migrate to the AWS SDK for Java 2.x to continue receiving new features, availability improvements, and security updates.
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
More Information
-
Amazon Pinpoint Campaigns in the Amazon Pinpoint User Guide
-
Creating Campaigns in the Amazon Pinpoint Developer Guide
-
Campaigns in the Amazon Pinpoint API Reference
-
Campaign in the Amazon Pinpoint API Reference
-
Campaign Activities in the Amazon Pinpoint API Reference
-
Campaign Versions in the Amazon Pinpoint API Reference
-
Campaign Version in the Amazon Pinpoint API Reference