from niadra.models.state import ObjectPush, ObjectPushRequest, Provenance, StateRef
# The system of record pushes what it knows; a field moves only under a greater version
niadra.api.push_objects(ObjectPushRequest(objects=[
ObjectPush(
ref=StateRef(type="item_variant", namespace="store", id="991"),
version=1042,
fields={"available": True, "price_sale": 199.9},
provenance=Provenance(source="live", source_observed_at=now),
),
]))// The system of record pushes what it knows; a field moves only under a greater version
await niadra.api.pushObjects({
objects: [
{
ref: { type: "item_variant", namespace: "store", id: "991" },
version: 1042,
fields: { available: true, price_sale: 199.9 },
provenance: { source: "live", source_observed_at: now },
},
],
});curl --request POST \
--url https://{space}.{region}.api.niadra.com/v1/objects/push \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"objects": [
{
"fields": {},
"provenance": {
"source_observed_at": "2023-11-07T05:31:56Z",
"scope": "global"
},
"ref": {
"id": "<string>",
"namespace": "<string>",
"type": "<string>",
"variant": "<string>"
},
"version": 4503599627370495,
"inputs": {},
"request_id": "<string>"
}
]
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
objects: [
{
fields: {},
provenance: {source_observed_at: '2023-11-07T05:31:56Z', scope: 'global'},
ref: {id: '<string>', namespace: '<string>', type: '<string>', variant: '<string>'},
version: 4503599627370495,
inputs: {},
request_id: '<string>'
}
]
})
};
fetch('https://{space}.{region}.api.niadra.com/v1/objects/push', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{space}.{region}.api.niadra.com/v1/objects/push",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'objects' => [
[
'fields' => [
],
'provenance' => [
'source_observed_at' => '2023-11-07T05:31:56Z',
'scope' => 'global'
],
'ref' => [
'id' => '<string>',
'namespace' => '<string>',
'type' => '<string>',
'variant' => '<string>'
],
'version' => 4503599627370495,
'inputs' => [
],
'request_id' => '<string>'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{space}.{region}.api.niadra.com/v1/objects/push"
payload := strings.NewReader("{\n \"objects\": [\n {\n \"fields\": {},\n \"provenance\": {\n \"source_observed_at\": \"2023-11-07T05:31:56Z\",\n \"scope\": \"global\"\n },\n \"ref\": {\n \"id\": \"<string>\",\n \"namespace\": \"<string>\",\n \"type\": \"<string>\",\n \"variant\": \"<string>\"\n },\n \"version\": 4503599627370495,\n \"inputs\": {},\n \"request_id\": \"<string>\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{space}.{region}.api.niadra.com/v1/objects/push")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"objects\": [\n {\n \"fields\": {},\n \"provenance\": {\n \"source_observed_at\": \"2023-11-07T05:31:56Z\",\n \"scope\": \"global\"\n },\n \"ref\": {\n \"id\": \"<string>\",\n \"namespace\": \"<string>\",\n \"type\": \"<string>\",\n \"variant\": \"<string>\"\n },\n \"version\": 4503599627370495,\n \"inputs\": {},\n \"request_id\": \"<string>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{space}.{region}.api.niadra.com/v1/objects/push")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"objects\": [\n {\n \"fields\": {},\n \"provenance\": {\n \"source_observed_at\": \"2023-11-07T05:31:56Z\",\n \"scope\": \"global\"\n },\n \"ref\": {\n \"id\": \"<string>\",\n \"namespace\": \"<string>\",\n \"type\": \"<string>\",\n \"variant\": \"<string>\"\n },\n \"version\": 4503599627370495,\n \"inputs\": {},\n \"request_id\": \"<string>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"applied": 123,
"out_of_set": 123,
"stale_version": 123,
"recorded": 0
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"detail": "<string>",
"request_id": "<string>",
"type": "about:blank"
}Push state
State from a system of record, up to 1,000 items: a field moves only when the item version is greater than the one that last wrote it. The state:push scope.
from niadra.models.state import ObjectPush, ObjectPushRequest, Provenance, StateRef
# The system of record pushes what it knows; a field moves only under a greater version
niadra.api.push_objects(ObjectPushRequest(objects=[
ObjectPush(
ref=StateRef(type="item_variant", namespace="store", id="991"),
version=1042,
fields={"available": True, "price_sale": 199.9},
provenance=Provenance(source="live", source_observed_at=now),
),
]))// The system of record pushes what it knows; a field moves only under a greater version
await niadra.api.pushObjects({
objects: [
{
ref: { type: "item_variant", namespace: "store", id: "991" },
version: 1042,
fields: { available: true, price_sale: 199.9 },
provenance: { source: "live", source_observed_at: now },
},
],
});curl --request POST \
--url https://{space}.{region}.api.niadra.com/v1/objects/push \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"objects": [
{
"fields": {},
"provenance": {
"source_observed_at": "2023-11-07T05:31:56Z",
"scope": "global"
},
"ref": {
"id": "<string>",
"namespace": "<string>",
"type": "<string>",
"variant": "<string>"
},
"version": 4503599627370495,
"inputs": {},
"request_id": "<string>"
}
]
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
objects: [
{
fields: {},
provenance: {source_observed_at: '2023-11-07T05:31:56Z', scope: 'global'},
ref: {id: '<string>', namespace: '<string>', type: '<string>', variant: '<string>'},
version: 4503599627370495,
inputs: {},
request_id: '<string>'
}
]
})
};
fetch('https://{space}.{region}.api.niadra.com/v1/objects/push', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{space}.{region}.api.niadra.com/v1/objects/push",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'objects' => [
[
'fields' => [
],
'provenance' => [
'source_observed_at' => '2023-11-07T05:31:56Z',
'scope' => 'global'
],
'ref' => [
'id' => '<string>',
'namespace' => '<string>',
'type' => '<string>',
'variant' => '<string>'
],
'version' => 4503599627370495,
'inputs' => [
],
'request_id' => '<string>'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{space}.{region}.api.niadra.com/v1/objects/push"
payload := strings.NewReader("{\n \"objects\": [\n {\n \"fields\": {},\n \"provenance\": {\n \"source_observed_at\": \"2023-11-07T05:31:56Z\",\n \"scope\": \"global\"\n },\n \"ref\": {\n \"id\": \"<string>\",\n \"namespace\": \"<string>\",\n \"type\": \"<string>\",\n \"variant\": \"<string>\"\n },\n \"version\": 4503599627370495,\n \"inputs\": {},\n \"request_id\": \"<string>\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{space}.{region}.api.niadra.com/v1/objects/push")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"objects\": [\n {\n \"fields\": {},\n \"provenance\": {\n \"source_observed_at\": \"2023-11-07T05:31:56Z\",\n \"scope\": \"global\"\n },\n \"ref\": {\n \"id\": \"<string>\",\n \"namespace\": \"<string>\",\n \"type\": \"<string>\",\n \"variant\": \"<string>\"\n },\n \"version\": 4503599627370495,\n \"inputs\": {},\n \"request_id\": \"<string>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{space}.{region}.api.niadra.com/v1/objects/push")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"objects\": [\n {\n \"fields\": {},\n \"provenance\": {\n \"source_observed_at\": \"2023-11-07T05:31:56Z\",\n \"scope\": \"global\"\n },\n \"ref\": {\n \"id\": \"<string>\",\n \"namespace\": \"<string>\",\n \"type\": \"<string>\",\n \"variant\": \"<string>\"\n },\n \"version\": 4503599627370495,\n \"inputs\": {},\n \"request_id\": \"<string>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"applied": 123,
"out_of_set": 123,
"stale_version": 123,
"recorded": 0
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"detail": "<string>",
"request_id": "<string>",
"type": "about:blank"
}Authorizations
nia_sk_...
Body
1 - 1000 elementsShow child attributes
Show child attributes
Response
Successful Response
How many items of the request each decision took, against the hot layer, with no database statement.
A shared object's item is applied when at least one of its fields moved forward: reads serve it at once,
and the consolidator writes it within a second with the same per-field rule, so the stored object never
disagrees with the answer. stale_version: every field was already written by this version or a greater
one, as a retried request finds. out_of_set: the object is not in the working set, and nothing is kept.
A subject's object is recorded: accepted as a system event about it, in the request's one statement,
and its fields move by the same rule when the event is applied.

