zabbix-apiにcurlでログインする

ZABBIX_URL=https://127.0.0.1
ZABBIX_USER=apiuser
ZABBIX_PASS=apipassword

API_KEY=`curl -k -d "{\"auth\":null,\"method\":\"user.login\",\"id\":1,\"params\":{\"user\":\"${ZABBIX_USER}\",\"password\":\"${ZABBIX_PASS}\"},\"jsonrpc\":\"2.0\"}" -H "Content-Type: application/json-rpc" ${ZABBIX_URL}/api_jsonrpc.php | sed -e "s/^.*\"result\":\"\([^\"]*\)\".*$/\1/g"`

curl -k -d "{\"auth\":\"${API_KEY}\",\"method\":\"user.logout\",\"id\":1,\"params\":[],\"jsonrpc\":\"2.0\"}" -H "Content-Type: application/json-rpc" ${ZABBIX_URL}/api_jsonrpc.php