Skip to content

Instantly share code, notes, and snippets.

@stask
Last active December 6, 2016 10:27
Show Gist options
  • Save stask/10469324 to your computer and use it in GitHub Desktop.
Save stask/10469324 to your computer and use it in GitHub Desktop.
PT Authentication in PHP
<?php
$api_key = ""; // here goes your api_key
$api_secret_key = ""; // here goes your api_secret_key
$timestamp = time();
$signature = md5($api_key . $api_secret_key . $timestamp);
$auth_header = "custom api_key=" . $api_key . ", signature=" . $signature . ", ts=" . $timestamp;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://prod.practitest.com/api/v1/automated_tests/upload_test_result.json");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{}"); // here goes the JSON you're uploading
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: " . $auth_header));
# on some older linux distros, our CA is not recognized,
# you can validate it by adding following line (libcurl will print debug info to STDERR)
# curl_setopt($ch, CURLOPT_VERBOSE, 1);
# To workaround it, you can add following line:
# curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
echo $result;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment