Merge AssetTrees¶
The Numbers Commits system operates analogously to the Git version control system. Each commit operation generates a corresponding AssetTree file.
The Read Asset History API returns all Commits and the associated AssetTrees of the asset from its blockchain records. This API further helps users merge all AssetTrees from commits based on the timestamp order, replace the old field with the updated values, and return one merged AssetTree. This effectively builds a comprehensive, unified record of asset histories. The required data format is the same as the commits
list from the output of Read Asset History. A full list of the AssetTrees before merging can be found in the AssetTrees
list from the response.
API Endpoint: https://eoqlryxobmjf9kw.m.pipedream.net
Cost: 0 NUM (free to use)
Method: POST
Description:
This endpoint accepts a JSON array of commit objects, each consisting of an assetTreeCid and timestampCreated.
Authentication:
This API requires a valid token for Authorization. The token should be passed in the headers of the request using the following format: "Authorization: token YOUR_CAPTURE_TOKEN"
Header:
Authorization: token $YOUR_CAPTURE_TOKEN (required)
Content-Type: application/json
Request Body (required):
The request body should be a JSON array of commit objects. Each commit object must have the following properties:
assetTreeCid (string): The unique identifier of the associated AssetTree.
timestampCreated (number): The Unix timestamp indicates when the commit was created.
Example
curl -X POST "https://eoqlryxobmjf9kw.m.pipedream.net" \
-H "Content-Type: application/json" \
-H "Authorization: token YOUR_CAPTURE_TOKEN" \
-d '[{"assetTreeCid":"bafkreiem3uo35xnip52bfg2bx6ghoevibg7t3yupfubxs5amkfnisgeveu", "timestampCreated":1683286764},{"assetTreeCid":"bafkreicoqqvglibw2dxyyopk7xfetiowcs7dy745cjtmbj3bvl7nmmy7di","timestampCreated":1683286945}]'
Response:
Concated AssetTree and all opened AssetTree objects
200: Cid/Nid retrieved successfully
400: Bad request
401: Unauthorized
403: Forbidden
500: Internal Server Error
Be sure to replace YOUR_CAPTURE_TOKEN
with your actual capture token.
In the example request body, two commit objects are being sent
[
{
"assetTreeCid": "bafkreiem3uo35xnip52bfg2bx6ghoevibg7t3yupfubxs5amkfnisgeveu",
"timestampCreated": 1683286764
},
{
"assetTreeCid": "bafkreicoqqvglibw2dxyyopk7xfetiowcs7dy745cjtmbj3bvl7nmmy7di",
"timestampCreated": 1683286945
}
]
{% tabs %} {% tab title="Python" %}
import requests
import json
url = "https://eoqlryxobmjf9kw.m.pipedream.net"
headers = {
"Content-Type": "application/json",
"Authorization": "token YOUR_CAPTURE_TOKEN" # replace 'YOUR_CAPTURE_TOKEN' with your actual token
}
data = [
{"assetTreeCid":"bafkreiem3uo35xnip52bfg2bx6ghoevibg7t3yupfubxs5amkfnisgeveu", "timestampCreated":1683286764},
{"assetTreeCid":"bafkreicoqqvglibw2dxyyopk7xfetiowcs7dy745cjtmbj3bvl7nmmy7di","timestampCreated":1683286945}
]
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.status_code)
print(response.json())
{% tab title="Javascript" %}
const url = "https://eoqlryxobmjf9kw.m.pipedream.net";
const headers = {
"Content-Type": "application/json",
"Authorization": "token YOUR_CAPTURE_TOKEN" // replace 'YOUR_CAPTURE_TOKEN' with your actual token
};
const data = [
{"assetTreeCid":"bafkreiem3uo35xnip52bfg2bx6ghoevibg7t3yupfubxs5amkfnisgeveu", "timestampCreated":1683286764},
{"assetTreeCid":"bafkreicoqqvglibw2dxyyopk7xfetiowcs7dy745cjtmbj3bvl7nmmy7di","timestampCreated":1683286945}
];
fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => console.log(data))
.catch((error) => console.error('Error:', error));