formulate Posted February 26, 2021 Share Posted February 26, 2021 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 More sharing options...
BitPoet Posted February 26, 2021 Share Posted February 26, 2021 Have you tried with the $raw_output parameter for hash_hmac? And just to make sure: you use your real spektrix username in place of "website" in setHeader, right? Link to comment Share on other sites More sharing options...
formulate Posted February 26, 2021 Author Share Posted February 26, 2021 Yes I've tried it with and without $raw_output. 'website' really is the API username. Link to comment Share on other sites More sharing options...
DanT Posted April 12, 2021 Share Posted April 12, 2021 @formulate Did you get Spektrix API working? I am having hard time integrating it. Having the same issue you faced! Can you please help, thanks; Link to comment Share on other sites More sharing options...
formulate Posted April 12, 2021 Author Share Posted April 12, 2021 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 More sharing options...
DanT Posted April 12, 2021 Share Posted April 12, 2021 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 More sharing options...
bernhard Posted April 13, 2021 Share Posted April 13, 2021 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 ? 2 Link to comment Share on other sites More sharing options...
AKiwi92 Posted October 18, 2021 Share Posted October 18, 2021 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! 1 Link to comment Share on other sites More sharing options...
Alex webdev Posted July 14, 2022 Share Posted July 14, 2022 @AKiwi92 thanks a lot for sharing code! Link to comment Share on other sites More sharing options...
tyrannosaurusRocks Posted August 16, 2022 Share Posted August 16, 2022 @AKiwi92 I just created an account to thank you. As @formulate mentioned: HORRIBLE documentation. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now