Aggregate API reference

The complete API reference for the Aggregates API

Load an aggregate

Before appending events to your aggregate you typically load (hydrate) it by loading all previous events for that particular aggregateId and fast-forward it into its current state.

To limit the size of the response the optional query parameters since and limit can be used.

Note that the parameters represents changes to the aggregate which does not necessarily correspond to the number of events that has been appended to it. The default limit is set to 1000.

Example

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  https://api.serialized.io/aggregates/order/99415be8-6819-4470-860c-c2933558d8d3
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.UriBuilder;

Client client = ClientBuilder.newClient();
  URI apiRoot = URI.create("https://api.serialized.io");

  Map aggregateResponse = client.target(apiRoot)
  .path("aggregates")
  .path("order")
  .path("99415be8-6819-4470-860c-c2933558d8d3")
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .get(Map.class);
using RestSharp;
using System;

var client = new RestClient("https://api.serialized.io");

var request = new RestRequest("aggregates/order/{aggregateId}", Method.GET)
   .AddUrlSegment("aggregateId", "99415be8-6819-4470-860c-c2933558d8d3")
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");

var response = client.Execute<Dictionary<string, Object>>(request);
const axios = require("axios");

const client = axios.create({
  baseURL: "https://api.serialized.io",
  headers: {
    "Serialized-Access-Key": "<YOUR_ACCESS_KEY>",
    "Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"
  }
});

client.get("aggregates/order/99415be8-6819-4470-860c-c2933558d8d3")
  .then(function (response) {
    // Handle response
  })
  .catch(function (error) {
    // Handle error
  });

Store events

Stores all events in the request atomically. All events must refer to the same aggregate id.

Example

curl -i https://api.serialized.io/aggregates/order/2c3cf88c-ee88-427e-818a-ab0267511c84/events \
  --header "Content-Type: application/json" \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  --data '
{
  "events": [
    {
      "eventType": "PaymentProcessed",
      "data": {
        "paymentMethod": "CARD",
        "amount": 1000,
        "currency": "SEK"
      }
    }
  ],
  "expectedVersion": 0
}
'
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

Client client = ClientBuilder.newClient();
  URI apiRoot = URI.create("https://api.serialized.io");

  Map eventBatch = ImmutableMap.of(
  "events", ImmutableList.of(
  ImmutableMap.of(
  "eventType", "PaymentProcessed",
  "data", ImmutableMap.of(
  "paymentMethod", "CARD",
  "amount", 1000,
  "currency", "SEK"
  )
  )
  ),
  "expectedVersion", "0"
  );

  Response response = client.target(apiRoot)
  .path("aggregates")
  .path("order")
  .path("3070b6fb-f31b-4a8e-bc03-e22d38f4076e")
  .path("events")
  .request(MediaType.APPLICATION_JSON_TYPE)
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .post(Entity.json(eventBatch));
using System;
using System.Collections.Generic;
using RestSharp;

var eventBatch = new Dictionary<string, Object>
{
    { "events", new List<Dictionary<string, Object>>
        {
            new Dictionary<string, Object>
            {
                { "eventType", "PaymentProcessed" },
                { "data", new Dictionary<string, Object>
                    {
                        { "paymentMethod", "CARD" },
                        { "amount", 1000 },
                        { "currency", "SEK" }
                    }
                }
            }
        }
    }
};

var postRequest = new RestRequest("aggregates/payments/{aggregateId}/events", Method.POST)
   .AddUrlSegment("aggregateId", "99415be8-6819-4470-860c-c2933558d8d2")
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");
   .AddJsonBody(eventBatch);

var response = client.Execute(postRequest);
const axios = require("axios");

const client = axios.create({
  baseURL: "https://api.serialized.io",
  headers: {
    "Serialized-Access-Key": "<YOUR_ACCESS_KEY>",
    "Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"
  }
});

const eventBatch = {
  events: [
    {
      eventType: "PaymentProcessed",
      data: {
        paymentMethod: "CARD",
        amount: 1000,
        currency: "SEK"
      }
    }
  ]
};

client.post("aggregates/order/99415be8-6819-4470-860c-c2933558d8d3/events", eventBatch)
  .then(function (response) {
    // Handle response
  })
  .catch(function (error) {
    // Handle error
  });

Check if an aggregate exists

Check if an aggregate exists

Example

curl -I \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  https://api.serialized.io/aggregates/order/99415be8-6819-4470-860c-c2933558d8d3
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

Client client = ClientBuilder.newClient();
  URI apiRoot = URI.create("https://api.serialized.io");

  Response response = client.target(apiRoot)
  .path("aggregates")
  .path("order")
  .path("99415be8-6819-4470-860c-c2933558d8d3")
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .head();
using RestSharp;
using System;

var client = new RestClient("https://api.serialized.io");

var request = new RestRequest("aggregates/order/{aggregateId}")
   .AddUrlSegment("aggregateId", "99415be8-6819-4470-860c-c2933558d8d3")
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");

var aggregateResponse = client.Head(request);
const axios = require("axios");

const client = axios.create({
  baseURL: "https://api.serialized.io",
  headers: {"Serialized-Access-Key": "<YOUR_ACCESS_KEY>"},
  headers: {"Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"}
});

client.head("aggregates/order/99415be8-6819-4470-860c-c2933558d8d3")
  .then(function (response) {
    // Handle response
  })
  .catch(function (error) {
    // Handle error
  });

Delete an aggregate

Permanently delete an aggregate, including all events.

Example

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  -X DELETE https://api.serialized.io/aggregates/order/d28bae0e-6f46-4c88-8935-b6e2c87ae4af
Response delete = client.target(apiRoot)
  .path("aggregates")
  .path("order")
  .path("99415be8-6819-4470-860c-c2933558d8d3")
  .queryParam("deleteToken", deleteToken)
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .delete();
var request = new RestRequest("aggregates/order/{aggregateId}", Method.DELETE)
   .AddUrlSegment("aggregateId", "99415be8-6819-4470-860c-c2933558d8d3")
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
   .AddQueryParameter("deleteToken", deleteToken);

var response = client.Execute<Dictionary<string, Object>>(request);
const requestConfig = {
  params: {
    deleteToken: deleteToken
  }
};

client.delete("aggregates/order/99415be8-6819-4470-860c-c2933558d8d3", requestConfig)
  .then(function (response) {
    // Handle response
  })
  .catch(function (error) {
    // Handle error
  });

Permanently deleting the aggregate using the delete token

This example permanently deletes an aggregate using a token that was returned from the response to the preceding delete request.

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  -X DELETE https://api.serialized.io/aggregates/order/d28bae0e-6f46-4c88-8935-b6e2c87ae4af?deleteToken=12c3780f-2dcb-340f-5532-5693be83f21c
Response delete = client.target(apiRoot)
  .path("aggregates")
  .path("order")
  .path("99415be8-6819-4470-860c-c2933558d8d3")
  .queryParam("deleteToken", deleteToken)
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .delete();
var request = new RestRequest("aggregates/order/{aggregateId}", Method.DELETE)
   .AddUrlSegment("aggregateId", "99415be8-6819-4470-860c-c2933558d8d3")
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
   .AddQueryParameter("deleteToken", deleteToken);

var response = client.Execute<Dictionary<string, Object>>(request);
const requestConfig = {
  params: {
    deleteToken: deleteToken
  }
};

client.delete("aggregates/order/99415be8-6819-4470-860c-c2933558d8d3", requestConfig)
  .then(function (response) {
    // Handle response
  })
  .catch(function (error) {
    // Handle error
  });

Delete all aggregates by type

Permanently deletes all aggregates, including all events for a given aggregate type.

Example

This example requests a delete token for deleting all aggregates for a given type

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  -X DELETE https://api.serialized.io/aggregates/order
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

Client client = ClientBuilder.newClient();
  URI apiRoot = URI.create("https://api.serialized.io");

  Map response = client.target(apiRoot)
  .path("aggregates")
  .path("order")
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .delete(Map.class);

  String deleteToken = (String) response.get("deleteToken");
using RestSharp;
using System;

var client = new RestClient("https://api.serialized.io");

var request = new RestRequest("aggregates/order", Method.DELETE)
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");

var response = client.Execute<Dictionary<string, Object>>(request);
var deleteToken = response.Data["deleteToken"]
const axios = require("axios");

const client = axios.create({
  baseURL: "https://api.serialized.io",
  headers: {"Serialized-Access-Key": "<YOUR_ACCESS_KEY>"},
  headers: {"Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"}
});

client.delete("aggregates/order")
  .then(function (response) {
    const deleteToken = response.data.deleteToken;
    // Use deleteToken
  })
  .catch(function (error) {
    // Handle error
  });

Permanently deleting the aggregate type using the delete token

This example permanently deletes an aggregate type using a delete token that was returned in the response to the preceding delete request.

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  -X DELETE https://api.serialized.io/aggregates/order?deleteToken=12c3780f-2dcb-340f-5532-5693be83f21c
var request = new RestRequest("aggregates/order", Method.DELETE)
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
   .AddQueryParameter("deleteToken", deleteToken);

var response = client.Execute<Dictionary<string, Object>>(request);
var request = new RestRequest("aggregates/order", Method.DELETE)
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
   .AddQueryParameter("deleteToken", deleteToken);

var response = client.Execute<Dictionary<string, Object>>(request);
const requestConfig = {
  params: {
    deleteToken: deleteToken
  }
};

client.delete("aggregates/order", requestConfig)
  .then(function (response) {
    // Handle response
  })
  .catch(function (error) {
    // Handle error
  });