#!/bin/bash  
# Install VPP application on device
# VPP app needs to be registered with the device serial number using the apple endpoint (https://vpp.itunes.apple.com/mdm/v2/assets/associate)  before one can install it on a device
source $MICROMDM_ENV_PATH
endpoint="v1/commands"
jq -n \
  --arg request_type "InstallApplication" \
  --arg udid "$1" \
  --arg itunes_store_id $2 \
  '.udid = $udid
  |.request_type = $request_type
  |.itunes_store_id = ($itunes_store_id|tonumber)
  |.options = {"purchase_method": 1}
  '|\
  curl $CURL_OPTS \
    -H "Content-Type: application/json" \
    -K <(cat <<< "-u micromdm:$API_TOKEN") "$SERVER_URL/$endpoint" -d@-