Authentication failed: Invalid signature.

37 views
Skip to first unread message

Roman Chyzh

unread,
Jun 8, 2017, 2:11:54 PM6/8/17
to MerchantCircle API
Currently I am trying to get some companies using your API and geo-endpoint.

I've  added lat and lon as query parameters to request url. And also have added api_key, timestamp and signature to query... 

As result I get error :

"response": {
    "status": 500,
    "seconds": 0.105,
    "errors": [
      {
        "msg": "Authentication failed: Invalid signature.",
        "code": 21
      }
    ]
  }

What is wrong? Cause previously generation of signature works fine...

Here is code-sample that generates signature (C# code)

using System;
using System.Security.Cryptography;
using System.Text;
public class Program
{
public static void Main()
{
var apikey = "testApiKey";
var secretKey = "someSecretKey";
var timestamp = DateTime.UtcNow.ToString("yyyyMMddHHmmssffff");
var sign = ToMD5(apikey + ":" + secretKey + ":" + timestamp);

Console.WriteLine("api_key={0}&timestamp={1}&signature={2}", apikey, timestamp, sign);
}
public static string ToMD5(string value, bool upperCase = true, string additionalString = null)
{
byte[] hash;
using (MD5 md5 = MD5.Create())
{
hash = md5.ComputeHash(Encoding.UTF8.GetBytes(value + additionalString));
}
return ToHex(hash,upperCase);
}
public static string ToHex(byte[] bytes, bool upperCase)
{
var result = new StringBuilder(bytes.Length * 2);
foreach (byte @byte in bytes)
{
result.Append(@byte.ToString(upperCase ? "X2" : "x2"));
}
return result.ToString();
}
}


Reply all
Reply to author
Forward
0 new messages