Store Events
post
https://api.serialized.io
/aggregates/{aggregateType}/{aggregateId}/events
Store Events

Example

cURL
Java
C#
Node
1
curl -i https://api.serialized.io/aggregates/order/2c3cf88c-ee88-427e-818a-ab0267511c84/events \
2
--header "Content-Type: application/json" \
3
--header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
4
--header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
5
--data '
6
{
7
"events": [
8
{
9
"eventType": "PaymentProcessed",
10
"data": {
11
"paymentMethod": "CARD",
12
"amount": 1000,
13
"currency": "SEK"
14
}
15
}
16
],
17
"expectedVersion": 0
18
}
19
'
Copied!
1
import com.google.common.collect.ImmutableList;
2
import com.google.common.collect.ImmutableMap;
3
import javax.ws.rs.client.Client;
4
import javax.ws.rs.client.ClientBuilder;
5
6
Client client = ClientBuilder.newClient();
7
URI apiRoot = URI.create("https://api.serialized.io");
8
9
Map eventBatch = ImmutableMap.of(
10
"events", ImmutableList.of(
11
ImmutableMap.of(
12
"eventType", "PaymentProcessed",
13
"data", ImmutableMap.of(
14
"paymentMethod", "CARD",
15
"amount", 1000,
16
"currency", "SEK"
17
)
18
)
19
),
20
"expectedVersion", "0"
21
);
22
23
Response response = client.target(apiRoot)
24
.path("aggregates")
25
.path("order")
26
.path("3070b6fb-f31b-4a8e-bc03-e22d38f4076e")
27
.path("events")
28
.request(MediaType.APPLICATION_JSON_TYPE)
29
.header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
30
.header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
31
.post(Entity.json(eventBatch));
Copied!
1
using System;
2
using System.Collections.Generic;
3
using RestSharp;
4
5
var eventBatch = new Dictionary<string, Object>
6
{
7
{ "events", new List<Dictionary<string, Object>>
8
{
9
new Dictionary<string, Object>
10
{
11
{ "eventType", "PaymentProcessed" },
12
{ "data", new Dictionary<string, Object>
13
{
14
{ "paymentMethod", "CARD" },
15
{ "amount", 1000 },
16
{ "currency", "SEK" }
17
}
18
}
19
}
20
}
21
}
22
};
23
24
var postRequest = new RestRequest("aggregates/payments/{aggregateId}/events", Method.POST)
25
.AddUrlSegment("aggregateId", "99415be8-6819-4470-860c-c2933558d8d2")
26
.AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
27
.AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");
28
.AddJsonBody(eventBatch);
29
30
var response = client.Execute(postRequest);
Copied!
1
const axios = require("axios");
2
3
const client = axios.create({
4
baseURL: "https://api.serialized.io",
5
headers: {"Serialized-Access-Key": "<YOUR_ACCESS_KEY>"},
6
headers: {"Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"}
7
});
8
9
const eventBatch = {
10
events: [
11
{
12
eventType: "PaymentProcessed",
13
data: {
14
paymentMethod: "CARD",
15
amount: 1000,
16
currency: "SEK"
17
}
18
}
19
]
20
};
21
22
client.post("aggregates/order/99415be8-6819-4470-860c-c2933558d8d3/events", eventBatch)
23
.then(function (response) {
24
// Handle response
25
})
26
.catch(function (error) {
27
// Handle error
28
});
Copied!
Copy link