Skip to content

Instantly share code, notes, and snippets.

@alecs
Created October 29, 2021 09:46
Show Gist options
  • Save alecs/b9507fb44895e10ebafab1d463b4009d to your computer and use it in GitHub Desktop.
Save alecs/b9507fb44895e10ebafab1d463b4009d to your computer and use it in GitHub Desktop.
Trudesk shell helper functions
sd_make() {
local accesstoken=""
local domain=""
local subject=$1
local description=$2
echo $1
echo $2
if [ -n "${subject}" -a -n "${description}" ]; then
curl "https://${domain}/api/v1/tickets/create" --compressed \
-H "authority: ${domain}" -H 'accept: application/json, text/plain, */*' \
-H 'content-type: application/json;charset=UTF-8' -H "origin: https://${domain}" \
-H 'sec-fetch-site: same-origin' -H 'sec-fetch-mode: cors' -H 'sec-fetch-dest: empty' \
-H "referer: https://${domain}/" -H "accesstoken: ${accesstoken}" \
--data-raw "{\"owner\":[\"5f44e36123bab0001253a6da\"],\"subject\":\"${subject}\",\"group\":\"5f4f4c24b980d700110ed062\",\"type\":\"5f44e36123bab0001253a6d5\",\"tags\":[],\"priority\":\"5f44e375e135820022635b17\",\"issue\":\"${description}\"}"
else
echo "Needs subject and description"
fi
}
sd_make_tsv() {
local tsfile=$1
if [ -f "${tsfile}" ]; then
IFS=$'\t'; egrep -v '^#' ${tsfile} | while read subject description; do
sd_make "${subject}" "${description}"
done
else
echo "No file at ${tsfile}"
fi
}
sd_search() {
local accesstoken=""
local domain=""
local search=$1
if [ -n "${search}" ]; then
OUT=`curl -s -G "https://${domain}/api/v1/tickets/search?" --compressed \
-H "authority: ${domain}" -H 'accept: application/json, text/plain, */*' \
-H 'content-type: application/json;charset=UTF-8' -H "origin: https://${domain}" \
-H 'sec-fetch-site: same-origin' -H 'sec-fetch-mode: cors' -H 'sec-fetch-dest: empty' \
-H "referer: https://${domain}/" -H "accesstoken: ${accesstoken}" \
--data-urlencode "search=${search}"`
if [ "$?" -eq 0 ]; then
echo "$OUT" | jq -r '.|.tickets|.[]|[.uid,.subject,.type.name,.group.name,if .status? == 0 then "📦" elif .status? == 1 then "⚡" elif .status? == 2 then "⏱️" else "🚪" end]|@tsv'
else
echo "Request failed"
fi
else
echo "No search param ?! Dafuq ?"
fi
}
sd_get() {
local accesstoken=""
local domain=""
OUT=`curl -s -G "https://${domain}/api/v1/tickets/" --compressed \
-H "authority: ${domain}" -H 'accept: application/json, text/plain, */*' \
-H 'content-type: application/json;charset=UTF-8' -H "origin: https://${domain}" \
-H 'sec-fetch-site: same-origin' -H 'sec-fetch-mode: cors' -H 'sec-fetch-dest: empty' \
-H "referer: https://${domain}/" -H "accesstoken: ${accesstoken}"`
if [ "$?" -eq 0 ]; then
echo "$OUT" | jq -r '.[]|[.uid,.subject,.type.name,.group.name,if .status? == 0 then "📦" elif .status? == 1 then "⚡" elif .status? == 2 then "⏱️" else "🚪" end]|@tsv'
else
echo "Request failed"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment