Java Quickstart

Welcome to mParticle! Let’s send your first event.

Step 1: Generate your API key

Create a Custom Feed on the Setup page to generate server-to-server API credentials.

Step 2: Add the mParticle SDK dependency

Our Java SDK is available via Gradle or Maven.


Add the SDK dependency to your build.gradle file.

dependencies {
  implementation 'com:mparticle:server-events-sdk:2+'


Add the SDK dependency to your pom.xml file.


Step 3: Call the Events API

Now you can integrate mParticle in your Java application.

// configure API
EventsApi api = new ApiClient(

// assemble an event batch
Batch batch = new Batch();
batch.userIdentities(new UserIdentities()

// create an event
CustomEvent customEvent = new CustomEvent().data(
        new CustomEventData()

// create attributes
Map customAttributes = new HashMap<>();
customAttributes.put("price", 33);

// add them to an event

// upload
Call<Void> singleResult = api.uploadEvents(batch);
Response<Void> singleResponse = singleResult.execute();
System.out.println("Returned code: " + singleResponse.code());

Step 4: Verify installation

Go to the Live Stream and watch new events come in as you run your application.

Next Steps

πŸŽ‰πŸŽ‰πŸŽ‰ Congrats on sending your first event to mParticle!

Some ideas on what to do next:

Was this page helpful?