Making API Requests with User Token

  • Using the key that is returned in the authentication response. Generate a new HMAC [signature] where the key returned in the response replaces the previously used PrivateKey.
  • Add an additional header value of x-ct-user-token to the HTTP Header and place the token that is returned in the authentication response into the header.
  • The user_id will need to be included in the request URL to identify the end-user when requesting the user-data related APIs.

The below examples show how the header and endpoint values will appear with a token and updated [signature] in the header.

Example Headers for an API request retrieving a user’s activity with user_id=123456789:

<!--?php
 
$curl = curl_init();
 
curl_setopt_array($curl, array(
  CURLOPT_URL =--> "https://api.crowdtwist.com/v2/users/123456789/activity_history/extended",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "x-ct-authorization: CTApiV2Auth publickey:signature",
    "x-ct-is-end-user: 1",
    "x-ct-timestamp: 1502382157536",
    "x-ct-user-token: d8cef561214c5c13fac48b692f4664ba"
  ),
));
 
$response = curl_exec($curl);
$err = curl_error($curl);
 
curl_close($curl);
 
if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
<!--?php
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL =--> "https://api.crowdtwist.com/v2/users/123456789/activity_history/extended",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "x-ct-authorization: CTApiV2Auth publickey:signature",
    "x-ct-is-end-user: 1",
    "x-ct-timestamp: 1502382157536",
    "x-ct-user-token: d8cef561214c5c13fac48b692f4664ba"
  ),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}