Tag: api

Getting started with the Logware API?

Before you start coding in your respective language, be sure to understand the steps to work with Logware. The logic flow when working with the Logware API has three basic steps. The steps are the same for committing your payload to Logware, regardless of it being a ‘hash’ value or ‘data’ value.

To get your free API key for testing, please contact service@logware.io.

First, you will authenticate with the API. You only need to do this for writing your payload to Logware. Reading from Logware does not require authentication, but it is throttled to prevent abuse.

Second, to write your payload to Logware, you would:

  1. Write the payload to the chain, get back a temporary Task Id.
  2. Using your temporary Task Id, read the chain and get back a permanent Transaction Id.
  3. Store your Transaction Id, you will need it in the future. It is your receipt and marker. Do not store or reuse the Task Id.

Third, in the future, you might want to read your payload from the chain. To do so, you need to the Transaction Id:

  1. Using your permanent Transaction Id, ask for a temporary Task Id.
  2. Using your temporary TaskId, read the chain to get the payload you are looking for.

Each action is a pair of POST/GET events. POST your request, get back a temporary Task Id. Then use the Task Id to GET the resulting Transaction Id or payload.

Sample BASH script of reading and writing data to the Lynx blockchain via the Logware API

The following code can be copy/pasted into a .sh file on your Linux command line. You must update the apiUsername and apiPassword with your own credentials (which you can get here). Be sure to make the file executable.

echo "Logware - Demo of reading and writing data to the Lynx blockchain via the Logware API with Linux BASH scripting."
# In order to access the API, please contact the Logware team
# at https://logware.io/#contact
apiUsername="{Update me with a Username}"
apiPassword="{Update me with a Password}"
# By default, use of the test environment is free. Understand that at any time
# the environment can be destroyed and all data will be lost.
# Support for passing a param via CLI to the script. A default value is set too.
[ -z "$1" ] && content="https://www.npr.org/2019/07/23/744582053/senate-approves-bill-to-prevent-sept-11-victims-fund-from-running-out-of-money"
echo "Content being written: '${content}'"
# Write section goes to https://api.logware.io/ and requires AUTH.
# Log in and get token
TOKEN=$(curl -s -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' --data '{"login":"'"$apiUsername"'","password":"'"$apiPassword"'"}' https://api.logware.io/api/users/authenticate | jq -r '.token')
echo "Logged in as '$apiUsername'"
# Now that we have the AUTH token, let's send the write request.
WRITE=$(curl -s -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization: Bearer $TOKEN" --data '{"env":"'"$apiEnvironment"'","data":"'"$content"'"}' https://api.logware.io/api/data)
WRITE="${WRITE%\"}" && WRITE="${WRITE#\"}" # Strip quotes from body
echo "WRITE Logware TaskId is '$WRITE'"
echo "Waiting for write to complete..."
# Sometimes a delay occurs, so let's wait for write. Now that was have the
# TaskId, we can query for the Lynx Transaction Id for future reference -
# both via Logware or offline directly with Lynx.
while [ "$TXID" = "null" ] ; do
	# Get the results of the write request
	TXID=$(curl -s -H 'Accept: application/json' -H "Authorization: Bearer $TOKEN" https://api.logware.io/api/data/$apiEnvironment/${WRITE} | jq -r '.Content[0]')
	echo "Lynx Transaction Id is '$TXID'"
	sleep 5
# Read section goes to https://api.logware.io/ and is anonymous. Notice the URL
# is different from the API endpoint for WRITE.
READ=$(curl -s -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' --data '{"env": "'"$apiEnvironment"'", "txid": "'"$TXID"'"}' https://api.logware.io/api/data/retrieve)
echo "READ TaskId is '$READ'"
echo "Waiting for read..."
# Due to an occasional delay, let's query until we get a response for the
# original data with this READ request.
while [ "$DATA" = "null" ] ; do
	# Get the results of the read request
	DATA=$(curl -s -H 'Accept: application/json' https://api.logware.io/api/data/retrieve/$apiEnvironment/${READ} | jq -r '.Content[0]')
	echo "DATA returned is '$DATA'"
	sleep 5