Skip to content

Instantly share code, notes, and snippets.

@grahampugh
Last active January 26, 2022 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grahampugh/e75573d81b6a6caebd486a6e1e1de5d4 to your computer and use it in GitHub Desktop.
Save grahampugh/e75573d81b6a6caebd486a6e1e1de5d4 to your computer and use it in GitHub Desktop.
Test the Jamf Pro dbfileupload endpoint.

Usage

dbfileupload.sh --jss someserver --user username --pass password --pkg /path/to/pkg.pkg

(don't include https:// or .jamfcloud.com)

#!/bin/bash
:<<DOC
Script for testing Jamf API dbfileupload endpoint using curl
DOC
usage() {
echo "Usage: dbfileupload.sh --jss someserver --user username --pass password --pkg /path/to/pkg.pkg"
echo "(don't include https:// or .jamfcloud.com)"
}
while test $# -gt 0 ; do
case "$1" in
-s|--jss)
shift
jss="$1"
;;
-u|--user)
shift
user="$1"
;;
-p|--pass)
shift
pass="$1"
;;
-f|--pkg)
shift
pkg_path="$1"
;;
*)
usage
exit
;;
esac
shift
done
if [[ ! $jss || ! $user || ! $pass || ! $pkg_path ]]; then
usage
exit
fi
temp_file="/tmp/api_tests.txt"
url="https://$jss.jamfcloud.com"
# generate a b64 hash of the credentials
credentials=$(printf "%s" "$user:$pass" | iconv -t ISO-8859-1 | base64 -i -)
# now try to post a package
echo
pkg=$(basename "$pkg_path")
http_response=$(
curl --request POST \
--header "authorization: Basic $credentials" \
--header 'Accept: application/xml' \
--header 'DESTINATION: 0' \
--header 'OBJECT_ID: -1' \
--header 'FILE_TYPE: 0' \
--header 'FILE_NAME: '"$pkg"'' \
--upload-file "$pkg_path" \
-i -o /dev/null \
--write-out %{http_code} \
"$url/dbfileupload"
)
echo
echo "HTTP response: $http_response"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment