• Hemanta Chakladar

    In php method,

    I get this error, “The Format of SigData is Invalid.”

    Because, $sig data is generated as 2016-01-04 18:36:00..52

    So, I changed the microtime(true) to micrtotime() and $sig_data = date(‘Y-m-d H:i:s.’) . substr($t,-3);

    I works fine for $sig_data as its generating $sig_data as 2016-01-04 18:58:36.916 and works for first time.

    Now I got the errror, “Server failed to authenticate the request. Make sure the value of the Authorization header is formed correctly including the signature.”

    Any help ?

    • omg007

      HI Hemanta,

      Can you please email domains@optimisemedia.com with your issue and we will get an example code to you.

      Thanks

      • aowie1

        I tried emailing this address but it is domain restricted. Do you have a different email address to recommend?

  • OM

    I get the following error
    mcrypt_encrypt(): Key of size 36 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported

    using php 5.6

    • Anoop Kumar

      Hi OM,

      Please use the below code for creating signature and calling the Optimise API Product feeds method in PHP. I have added the test API Key & Private Key in the code. So, the script gives result for test affiliate(156872). Please replace the API key, Private Key, AgencyID, AID & other parameters with yours.

      setData($data);

      $this->setBlockSize($blockSize);

      $this->setKey($key);

      $this->setMode($mode);

      $this->setIV(“”);

      }

      /**

      *

      * @param type $data

      */

      public function setData($data) {

      $this->data = $data;

      }

      /**

      *

      * @param type $key

      */

      public function setKey($key) {

      $this->_key = $key;

      }

      /**

      *

      * @param type $blockSize

      */

      public function setBlockSize($blockSize) {

      switch ($blockSize) {

      case 128:

      $this->cipher = MCRYPT_RIJNDAEL_128;

      break;

      case 192:

      $this->cipher = MCRYPT_RIJNDAEL_192;

      break;

      case 256:

      $this->cipher = MCRYPT_RIJNDAEL_256;

      break;

      }

      }

      /**

      *

      * @param type $mode

      */

      public function setMode($mode) {

      switch ($mode) {

      case AES::M_CBC:

      $this->mode = MCRYPT_MODE_CBC;

      break;

      case AES::M_CFB:

      $this->mode = MCRYPT_MODE_CFB;

      break;

      case AES::M_ECB:

      $this->mode = MCRYPT_MODE_ECB;

      break;

      case AES::M_NOFB:

      $this->mode = MCRYPT_MODE_NOFB;

      break;

      case AES::M_OFB:

      $this->mode = MCRYPT_MODE_OFB;

      break;

      case AES::M_STREAM:

      $this->mode = MCRYPT_MODE_STREAM;

      break;

      default:

      $this->mode = MCRYPT_MODE_ECB;

      break;

      }

      }

      /**

      *

      * @return boolean

      */

      public function validateParams() {

      if ($this->data != null &&

      $this->_key != null &&

      $this->cipher != null) {

      return true;

      } else {

      return FALSE;

      }

      }

      public function setIV($IV) {

      $this->IV = $IV;

      }

      protected function getIV() {

      if ($this->IV == “”) {

      $this->IV = mcrypt_create_iv(mcrypt_get_iv_size($this->cipher, $this->mode), MCRYPT_RAND);

      $this->IV = mb_convert_encoding($this->IV,’UTF-8′);

      }

      return $this->IV;

      }

      /**

      * @return type

      * @throws Exception

      */

      public function encrypt() {

      if ($this->validateParams()) {

      $block = mcrypt_get_block_size($this->cipher, $this->mode);

      $padding = $block – (strlen($this->data) % $block);

      $this->data .= str_repeat(chr($padding), $padding);

      return trim(base64_encode(

      mcrypt_encrypt(

      $this->cipher, $this->_key, $this->data, $this->mode, $this->getIV())));

      } else {

      throw new Exception(‘Invalid params!’);

      }

      }

      /**

      *

      * @return type

      * @throws Exception

      */

      public function decrypt() {

      if ($this->validateParams()) {

      return trim(mcrypt_decrypt(

      $this->cipher, $this->_key, base64_decode($this->data), $this->mode, $this->getIV()));

      } else {

      throw new Exception(‘Invalid params!’);

      }

      }

      }

      date_default_timezone_set(“UTC”);

      $t = microtime(true);

      $micro = sprintf(“%03d”,($t – floor($t)) * 1000);

      $utc = gmdate(‘Y-m-d H:i:s.’, $t).$micro;

      //$sig_data= date(‘Y-m-d H:i:s.’, substr($t, 0, -3)) . substr($t,-3);

      $sig_data= $utc;

      //########################Please Add your API Key & Private Key here to test##################################################

      $api_key=’546798AB-03B9-4C30-82C0-1EC52E833A6F’;

      $private_key=’493be0722b664bdd8686bd477b7da083′;

      //############################################################################################################################

      $mode=’cbc’;

      $blockSize = 128;

      $aes = new AES($sig_data, $private_key, $blockSize, $mode);

      $enc = $aes->encrypt();

      //############# This is a test url. You have to change the parameters according to your need #######################

      $url=”https://api.omgpm.com/network/OMGNetworkApi.svc/v1.1/ProductFeeds/GetProducts?”. http_build_query(array(

      ‘AgencyID’ => 95,

      ‘AID’=>156872,

      ‘MID’=> ”,

      ‘Keyword’=>’LED TV’,

      ‘MinPrice’=>2000,

      ‘MaxPrice’=>”,

      ‘Currency’=>’INR’,

      ‘Brand’=>”,

      ‘DiscountedOnly’=>’False’,

      ‘MPN’=>”,

      ‘ProductSKU’=>”,

      ‘FeedID’=>”,

      ‘Key’ => $api_key,

      ‘Sig’ => $enc,

      ‘SigData’ => $sig_data

      ));

      echo “URL: “.$url.””;

      $headers = array(

      “Content-Type: application/json”,

      “Accept: application/json”,

      “Access-Control-Request-Method: GET”

      );

      $ch = curl_init();

      curl_setopt($ch, CURLOPT_URL, $url);

      curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

      $result = curl_exec($ch);

      $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

      print_r($result);

      ?>

  • OM

    Now I get
    “Server failed to authenticate the request. Make sure the value of the Authorization header is formed correctly including the signature.”

    Mind you I am calling http://api.omgpm.com/network/OMGNetworkApi.svc/v1.1/GetAccounts/ValidateLogin

  • Parveen Dutt kaushik

    Hi, I have a website(wordpress) & Optimise(OMGPM) account, Now i want to integrate api with my site. Anyone can do this job if you are interested please drop me a mail with your amount and time.

    Email Id: parveenkaushik.in@gmail.com
    Website anyshopdeal.com

  • Yui Rui

    Do you guys have an example for NodeJS? I seem to always get error 403…

  • ANKIT KATIYAR

    I have used java code to generate key but my generated key is longer than generated in sandbox

    Ex:
    Data: 2016-05-23 15:42:54.980
    Sig By above Code: U0xsAPb9MaWxGaMOFEt1EWI%2BTq9WHwc%2BWF%2BaGUpK06I%3D

    Sandbox: 7d74b0595c4fac8a1da5262cced95132

  • Kar

    Hi , I am getting an error – Server failed to authenticate the request. The signature expired.
    Url is http://api.omgpm.com/network/OMGNetworkApi.svc/v1.2/ProductFeeds/GetMerchants?AgencyID=118&aid=xxxxx&Key=xxxxx&Sig=xxx&SigData=2017-03-06%2010:57:48.721&output=json

    Please help !

  • Vijay Bharati

    how to generate api key

    • Please login to your account and click My details > API Key

      Thanks

  • Shailesh Negi

    Getting below mentioned Error.

    “Server failed to authenticate the request. Make sure the value of the Authorization header is formed correctly including the signature.”

    https://api.omgpm.com/network/OMGNetworkApi.svc/v1.2/GetAccounts/ValidateLogin?Key=XXXXXXXX&Sig=XXXXXXXX&SigData=2014-11-21 18:44:13.56&output=json

  • Shailesh Negi

    Getting below mentioned Error For Login API

    {“Message”:”There was an error processing the request.”,”StackTrace”:””,”ExceptionType”:””}

    • Samith N

      use “https” in api url
      for me it worked… spent hours to find it…

Translate »