Read commits via API

Reading commits via API is the simplest way to access asset histories. Here is an example of how you can use the curl command to make a GET request to the specified endpoint using your Capture Token and the Nid of the asset you want to query. If you do not have a Capture Token yet, please follow the instruction and create one.

API Endpoint: https://eohakmlw1xjl7ut.m.pipedream.net

Cost: 0, free to use

Method: GET

Description:
This endpoint allows you to retrieve information about a specific nid. 
Replace "NID_TO_QUERY" with the specific nid you wish to retrieve information about.

Parameters:

Parameter	Type	Required	Description
nid	        text	Yes	        The nid of the asset to retrieve
testnet	        text	No	        true to query on Testnet (snow)
tmp_token       text    No              tmp_token to access private assets

Authentication:
The API requires a valid token for Authorization. 
You can pass it in the headers of the request using the following format: 
"Authorization: token YOUR_CAPTURE_TOKEN"

Headers:
Content-Type: application/json
Authorization: token YOUR_CAPTURE_TOKEN

Examples:
curl -X GET -H "Content-Type: application/json" \
            -H "Authorization: token YOUR_CAPTURE_TOKEN" \
            "https://eohakmlw1xjl7ut.m.pipedream.net?nid=NID_TO_QUERY"
            
Response:
{
    "nid": AssetNid,
    "commits": [
        {
              "transaction": COMMIT_TRANSACTION_HASH,
              "assetTreeCid": ASSET_TREE_NID,
              "assetTreeSha256": ASSET_TREE_SHA256,
              "assetTreeSignature": ASSET_TREE_SIGNATURE,
              "author": AUTHOR_WALLET_ADDRESS,
              "committer": COMMITTER_WALLET_ADDRESS,
              "provider": NID_OF_PROVIDER_PROFILE,
              "timestampCreated": UNIX_TIMESTAMP,
              "action": ACTION_DESCRIPTION,
              "actionName": THE_REAL_ACTION_NAME,
              "actionNid": THE_NID_OF_ACTION,
              "actionResult": ACTION_RESULT_URL,
              "abstract": ACTION_DESCRIPTION
         }, ...
   ]
 }

Detailed explanation of the commit message can be found on the Commit page. In this example, you would replace YOUR_CAPTURE_TOKEN with your actual Capture token and NID_TO_QUERY with the Nid of the asset you want to retrieve information for. More examples can be found below:

import requests

# Define the URL for the API endpoint
url = "https://eohakmlw1xjl7ut.m.pipedream.net"

# Define headers for the request, including the Capture Token
headers = {
    "Content-Type": "application/json",
    "Authorization": "token " + YOUR_CAPTURE_TOKEN
}

# Define the query parameter for the nid to be queried
params = {"nid": NID_TO_QUERY, "testnet": "true"}

# Send the GET request to the API
response = requests.get(url, headers=headers, params=params)

# Check if the request was successful
if response.status_code != 200:
    print(f"Error: {response.status_code} - {response.text}")
else:
    # Parse the response as JSON
    json_data = response.json()

    # Print the "nid" of the asset from the JSON data
    print("nid:", json_data["nid"])

    # Print the first commit from the "commits" array in the JSON data
    print("First commit:", json_data["commits"][0])

Last updated