This post goes over how to curl Certica’s Academic Benchmarks API. We’re using AB Connect 4.1.
Credentials
Set the partner ID and key:
PARTNER_ID=demo4
PARTNER_KEY=exMSobPnS7F0s/u/aKtakg
Authentication
Generate your auth signature. The signature consists of:
- expires*
- user id
- HTTP method
- resource
*The access expiration expressed in seconds since epoch. This is the only required field.
Expires
On Linux, to get expires 1 hour from now:
AUTH_EXPIRES=$(date -d 'today 1 hour' +%s)
On Mac, to get expires 1 hour from now:
AUTH_EXPIRES=$(date -j -v +1H -f "%Y-%m-%d" $(date +%Y-%m-%d) +%s)
Message
Generate your message by concatenating the fields with a newline character:
MESSAGE=$(echo -e "$AUTH_EXPIRES\n$USER_ID\n$HTTP_METHOD\n$RESOURCE")
Signature
Hash the message with HMAC SHA-256 and encode the binary output using Base64:
AUTH_SIGNATURE=$(
echo -n $MESSAGE | \
openssl sha256 -hmac $PARTNER_KEY -binary | \
base64
)
cURL
The standards endpoint is https://api.abconnect.certicaconnect.com/rest/v4.1/standards/
:
STANDARDS_URL="https://api.abconnect.certicaconnect.com/rest/v4.1/standards/"
URL-encode the query string fields before making the curl request:
curl --get \
--data-urlencode "partner.id=$PARTNER_ID" \
--data-urlencode "auth.signature=$AUTH_SIGNATURE" \
--data-urlencode "auth.expires=$AUTH_EXPIRES" \
$STANDARDS_URL
The required query string fields are:
partner.id
auth.signature
auth.expires
To pretty-print the JSON, you can parse the response output with jq
:
curl --get --silent \
--data-urlencode "partner.id=$PARTNER_ID" \
--data-urlencode "auth.signature=$AUTH_SIGNATURE" \
--data-urlencode "auth.expires=$AUTH_EXPIRES" \
$STANDARDS_URL \
| jq