Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Alfresco REST API - List nodes by noderef
# /bin/bash
set -e
export http_proxy=
ALF_HOST="http://localhost:8080/"
ALF_USER="admin"
ALF_PASS="secret"
if [ -z "$1" ]; then
echo "Usage: alf-rest-search.sh <TYPE|SITE|ASPECT|property|TEXT|ISNULL|ISNOTNULL> <object>"
echo
echo " ./alf-rest-search.sh TYPE cm:content"
echo " ./alf-rest-search.sh TYPE cm:folder"
echo " ./alf-rest-search.sh ASPECT qshare:shared"
echo " ./alf-rest-search.sh ASPECT cm:indexControl"
echo " ./alf-rest-search.sh SITE swsdp"
echo " ./alf-rest-search.sh name 'Project*'"
echo " ./alf-rest-search.sh cm:title 'Project'"
echo " ./alf-rest-search.sh cm:creator 'System'"
exit 0
fi
TICKET=`curl -s "${ALF_HOST}/alfresco/service/api/login?u=${ALF_USER}&pw=${ALF_PASS}&format=json" | jq -r '.data.ticket'`
QUERYC=$(cat <<EOF
{
"query": {
"language": "afts", "query": "name:* AND $1:\"$2\""
}
}
EOF
)
numrows=`curl -s -X POST -d "$QUERYC" --header 'Content-Type: application/json' --header 'Accept: application/json' $ALF_HOST/alfresco/api/-default-/public/search/versions/1/search?alf_ticket=$TICKET | jq '.list.pagination.totalItems'`
echo "# $numrows"
rw="1000"
st="0"
cn="0"
if [ "$numrows" -gt "0" ]; then
while [ $st -lt $numrows ]; do
QUERYP=$(cat <<EOF
{
"query": {
"language": "afts", "query": "name:* AND $1:\"$2\""
},
"paging": {
"maxItems": "$rw", "skipCount": "$st"
}
}
EOF
)
curl -s -X POST -d "${QUERYP}" \
--header 'Content-Type: application/json' --header 'Accept: application/json' \
$ALF_HOST/alfresco/api/-default-/public/search/versions/1/search?alf_ticket=$TICKET | jq -r '.list.entries[].entry | "\(.id) \(.nodeType) \(.name)"'
cn=$[$cn+1]
st=$[$cn*$rw]
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.