1. Home
  2. Docs
  3. Documentation
  4. Authentication
  5. Authenticating requests

Authenticating requests

All requests need to be authenticated. If an API key isn’t provided, or an invalid API key is used, an error will be returned.

Unauthenticated response

{
    "Status": "401",
    "Message": "Not authorized"
}

Authentication example

API keys are added to the request header, with a key of “Authorization”.

CURL

curl -v -H @{'Authorization' = 'api_key'} https://api.retrocrypt.com/rest/v1/endpoint

PHP

<?php
$endpoint = '/game/random';
$api_key = 'my_secret_key';

$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'https://api.retrocrypt.com/rest/v1'.$endpoint);
curl_setopt($c, CURLOPT_HTTPGET, true);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Accept: application/json',
    'Authorization: '.$api_key,
));
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);

$result = json_decode(curl_exec($curl));
curl_close($curl);

WordPress

$endpoint = '/game/random';
$api_key = 'my_secret_key';

$resp = wp_remote_get('https://api.retrocrypt.com/rest/v1'.$endpoint, array(
    'headers' => array(
        'Authorization' => $api_key,
    )
));