• Register

Calculating the Contract Pricing Signature

In order to request any special rates associated with your account, we need to associate an API request to a web user account.  To acheive this you will need to have registered on our websites and provide us with your Username.

Once we have your Username we can join the web account to the Product Search API so that any special rates can be retrieved. We will supply you with a Secret Key and Customer ID.

Please Note: The REST call is built over our SOAP API and the Contract Pricing request uses some legacy details when it comes to generating a signature - specifically, it needs to reference the equivelant SOAP Function that is being called by the REST API when generating a signature  The REST and SOAP equivalents are below.

REST Function equivalent SOAP Function (operation name)
term=any searchByKeyword
term=id searchByPremierFarnellPartNumber
term=manuPartNum searchByManufacturerPartNumber

In order to retrieve Contract Pricing, the Product Search API requires three additional parameters passing in the URL.; they are

  • userInfo.signature: This is generated by concatenating the Operation Name (see above table) + timestamp  and then using the secret key generate a HMAC SHA1 hash using the resultant Base64 option (useful reference: http://hash.online-convert.com/sha1-generator ). 

     ***Please note the following important information to avoid signature errors:

    1. The signature is operation specific and therefore needs to match the request "term" being made.
    2. When a  Signature is created using the HMAC SHA1 process, it may contain special characters (such as a + sign) which will need to be URL encoded - otherwise the signature will be misinterpretted and will result in a failed call (useful sites: http://meyerweb.com/eric/tools/dencoder/https://www.w3schools.com/tags/ref_urlencode.ASP

  • userInfo.timestamp: Universal time Constant (UTC) in the format of yyyy-MM-ddThh:mm:ss.sss. e.g. 2009-02-0T15:45:40.254. This has a tolerance of + or – 10 minutes in relative to search service system clock
  • userInfo.customerId: This is a number generated by us and assigned to the customer, e.g. 999123

 

PHP Code example for signature generation

<!DOCTYPE html>

<html>

<body>

<?php

$secret_key = "enter the secret key";

$timestamp =  gmdate("Y-m-d\TH:i:s.v"); // current timestamp

$data = "searchByPremierFarnellPartNumber".$timestamp; // concatenating string

$signature = hash_hmac("sha1", $data, $secret_key); // hmac sha1 signature generation

$sign_hex = hex2bin($signature); // converts a string of hexadecimal values to ASCII characters

$sign_encoded = base64_encode($sign_hex); // base64 encoded

$signature_url_encoded = urlencode($sign_encoded);  // signature url encoded

echo "Signature: $signature_url_encoded";

echo "\nTimestamp: $timestamp";

?>
</body>

</html>