Jump to content

wireHTTP API authorization issue


formulate
 Share

Recommended Posts

I'm at the end of my rope! I've been trying to use a 3rd party API that requires authorization. I've tried a zillion different ways in both cURL and wireHTTP. cURL always tells me the signature is wrong. wireHTTP returns 401 unauthorized.

Here's the brief documentation for authorization with the API: https://integrate.spektrix.com/docs/authentication

Here's the latest version of my wireHTTP code:

$date = date(DATE_RFC1123);
$string = "GET\n/sidwilliams/api/v3/customers/I-KS22-363P/\n$date";
$string = utf8_encode($string);
$key = base64_decode('XXXX');
$signature = base64_encode(hash_hmac('sha1', $string, $key)); 

$http = new WireHttp();
$http->setHeader('Host', 'system.spektrix.com');
$http->setHeader('Date', $date);
$http->setHeader('Authorization', 'SpektrixAPI3 website:' . $signature);
$response = $http->get('https://system.spektrix.com/sidwilliams/api/v3/customers/I-KS22-363P/'); 

if($response === false) {
    echo $http->getError(); 
}else{
	echo $response;
}

If anyone is interested in seeing my cURL, I can post that too.

Thanks!

Link to comment
Share on other sites

  • 1 month later...

I did get it working! It took A LOT of time and money, but I eventually got it working. Their documentation is A) terrible and even B) misleading. I'll shoot you a message and we can pick this up in email (it'll be easier that way).

Link to comment
Share on other sites

15 minutes ago, formulate said:

I did get it working! It took A LOT of time and money, but I eventually got it working. Their documentation is A) terrible and even B) misleading. I'll shoot you a message and we can pick this up in email (it'll be easier that way).

Thank you so much!! you rock

Link to comment
Share on other sites

15 hours ago, formulate said:

I'll shoot you a message and we can pick this up in email (it'll be easier that way).

But it will not help others that may have the same problem in the future 😉 

  • Like 2
Link to comment
Share on other sites

  • 6 months later...

Okay so just to help others out here is the PHP snippet that I managed to get working making a cURL request to the Spektrix V3 API
 

<?php
$date = new DateTime('NOW');
$date = $date->format('D, d M Y H:i:s \G\M\T');
$LoginName = "API USERNAME";
$SecretKey = "API SECRET KEY";
$StringToSign = "GET\nFULL URL YOU ARE QUERYING\n".$date;


$StringToSignEncoded = utf8_encode( $StringToSign );
$SecretBase64Decoded = base64_decode($SecretKey);
$sha1 = hash_hmac('sha1', $StringToSignEncoded, $SecretBase64Decoded,true);

$Signature = base64_encode($sha1);

$Authorization = "SpektrixAPI3 " . $LoginName . ":" . $Signature;

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'FULL URL YOU ARE QUERYING',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Authorization:'.$Authorization,
    'Date:'.$date
  ),
));
$response = curl_exec($curl);
var_dump($response);
curl_close($curl);
?>

I hope this helps someone else who was stuck on this one!

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...