Skip to content

Instantly share code, notes, and snippets.

@sauntimo
Last active December 21, 2018 08:22
Show Gist options
  • Save sauntimo/557acde6784683fb5b5f58ad5d989c1f to your computer and use it in GitHub Desktop.
Save sauntimo/557acde6784683fb5b5f58ad5d989c1f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Setup required variables
host="d51ts.vehicles.api.comcar.co.uk"
path="/v0/makes/lamborghini/models/aventador/vehicles/"
api_key="cheesecake"
api_secret="fish"
nonce="making something up here"
dev_ip="192.168.0.24"
timestamp=$(date -u +%s)
# concat variables for ease of use
hmac_key="$api_key$api_secret$nonce$timestamp$dev_ip"
# get the sha256 hash of the concatted vbls
# only return frist 64 characters as the rest of the output is unnecessary
hmac=$( echo -n "$hmac_key" | sha256sum | head -c 64 )
# make the request, adding the necessary headers
# k flag means insecure mode ie ignore invalid/self-signed ssl certificate
# i flag means include headers in output, don't add if you want to pretty print JSON
curl -k https://{$host}${path} \
-H "hash: $hmac" \
-H "key: $api_key" \
-H "nonce: $nonce" \
-H "time: $timestamp" \
-H "x-timestamp: $timestamp" | \
# pipe the output to python's JSON pretty printer
python -m json.tool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment