Script that makes an API call to and parses the response to get a URL from where to download another file This is my first script and I am having a hard time writing the shortest possible code.

exportsData=$(curl -X GET \
 -H 'Accept: application/vnd.xxxxx+json; version=3.0' \
 -H 'Authorization: Bearer RCexxxxxxxxxxxxxxxxxxxxxxxxxcVefI5mWy' \
 -H 'Content-Type: application/json' \
https://api.xxxx.com/apps/9xxxxxxxxx15f96fe/exports)
status=$(echo $exportsData | jq '.[0].status')
downloadURL=$(echo $exportsData | jq '.[0].download_url') 
 export ENCRYPTED_AES_KEY=$(echo $exportsData | jq '.[0].encrypted_aes_key')
export AES_IV=$(echo $exportsData | jq '.[0].aes_iv')

export ENCRYPTED_TARBALL=encryptedChatDump.tar.gz.enc
 $(curl -X GET -o ENCRYPTED_TARBALL \
 -H 'Accept: application/vnd.xxxxx+json; version=3.0' \
 -H 'Authorization: Bearer RCexxxxxxxxxxxxxxxxxxxxxxxxxcVefI5mWy' \
 -H 'Content-Type: application/json' \
https://storage.googleapis.com/someUrlWhereTheFileIsBeingDownloadedFrom)

export OUTPUT_TAR=finalChatDumpUnencrypted.tar.gz
export PRIVATE_KEY_PATH=~/.ssh/id_rsa
Don't repeat yourself

The two curl commands have significant repeated parts.
You can extract that to a function.

For example:

mycurl() {
    curl -X GET \
         -H 'Accept: application/vnd.xxxxx+json; version=3.0' \
         -H 'Authorization: Bearer RCexxxxxxxxxxxxxxxxxxxxxxxxxcVefI5mWy' \
         -H 'Content-Type: application/json' \
        "$@"
}


And then use it like this:

exportsData=$(mycurl https://api.xxxx.com/apps/9xxxxxxxxx15f96fe/exports)
...
mycurl -o "$ENCRYPTED_TARBALL" https://storage.googleapis.com/someUrlWhereTheFileIsBeingDownloadedFrom


Use here-strings instead of echo ... | ...

Instead of this:

echo $exportsData | jq '.[0].status'


It's better to use here-strings, like this:

jq '.[0].status' &lt;&lt;&lt; "$exportsData"


Small bug

Instead of this:


export ENCRYPTED_TARBALL=encryptedChatDump.tar.gz.enc
 $(curl -X GET -o ENCRYPTED_TARBALL \
...



You probably meant to write this:

export ENCRYPTED_TARBALL=encryptedChatDump.tar.gz.enc
 $(curl -X GET -o "$ENCRYPTED_TARBALL" \
...


Pointless variables?

These variables are set at the end of the script, but what for?


export OUTPUT_TAR=finalChatDumpUnencrypted.tar.gz
export PRIVATE_KEY_PATH=~/.ssh/id_rsa