Follow

Script Example - Pull data from the file_log for specfic day

This information will show you how to pull data from the file_log section of the API for a specific day. You will need to define the following: 

site - this is your .ftptoday.com or .govftp.com hostname
api_token - This is the token created for the account that is going to run the query.

#!/bin/env bash
site="youriste.govftp.com"
api_token="Insert-API-Token-Here"

if [[ -z "$1" ]] ; then
echo "Usage: $0 yyyy-mm-dd"
echo ""
exit 1
fi

output_file="/tmp/log1_$$.txt"
start_date=`date -d "$1" '+%Y-%m-%d'`
end_date=`date -d "$1 +1 day" '+%Y-%m-%d'`

endpoint="https://$site/api/file_log/"
json_header="Accept: application/vnd.api+json"
api_key_header="X-API-KEY: $api_token"

filter="filter[]=date_time,>=,$start_date&filter[]=date_time,<,$end_date"
response=`curl -g "$endpoint?page=1,1&sort=id&$filter" -H "$json_header" -H "$api_key_header" -s`
if [[ `echo "$response" | grep -c '"errors":'` -eq "1" ]]; then
echo $response
exit
fi

meta_count=`echo $response | sed -n 's/.*"meta":{"count":\([0-9]\+\)}.*/\1/p'`
echo "$meta_count entries found"

for ((i = 0 ; i < meta_count ; i+=1000))
do
filter="filter[]=id,>=,$last_id&filter[]=date_time,<,$end_date"
curl -s -g "$endpoint?page=1,1000&sort=id&$filter" -H "$json_header" -H "$api_key_header" -o - | python -m json.tool >> $output_file
done

if [[ -e "$output_file" ]] ; then
echo "Responses stored at: $output_file"
less -m $output_file 2>/dev/null
else
echo "No match for $start_date."
fi