Example in Python 3.x
From version 4.0 the recommended authentication method is JWT and not the URL signing described below
Example of how to sign a request in Python 3.x
Python
from random import randint from datetime import datetime from urllib.parse import quote_plus import hashlib token = "65476hgfdsdf56656baa8b566c28" print("Token:\n {0}\n".format(token)) secret = "gsfgf65sdsa4a8" print("Secret:\n {0}\n".format(secret)) request = "http://site.meridix.se/api/customer/listcustomers" verb = "GET" print("Request:\n {0}\n".format(request)) nonce = randint(100000, 999999).__str__() print("Nonce:\n {0}\n".format(nonce)) timestamp = datetime.utcnow().strftime("%Y%m%d%H%M%S") print("Timestamp:\n {0}\n".format(timestamp)) parameters = [ "auth_nonce=" + nonce, "auth_timestamp=" + timestamp, "auth_token=" + token ] parameters.sort() print("Parameters:\n {0}\n".format(parameters)) parametersConcated = "&".join(parameters) print("ParametersConcated:\n {0}\n".format(parametersConcated)) parametersConcatedEncoded = quote_plus(parametersConcated) print("ParametersConcatedEncoded:\n {0}\n".format(parametersConcatedEncoded)) requestEncoded = quote_plus(request) print("RequestEncoded:\n {0}\n".format(requestEncoded)) # IMPORTANT - The GET&-prefix must be change to POST& etc. when using different HTTP Verbs than GET. verbRequestQuery = verb.upper() + "&" + requestEncoded + "&" + parametersConcatedEncoded + "&" + secret; print("VerbRequestQuery:\n {0}\n".format(verbRequestQuery)) signature = hashlib.md5(verbRequestQuery.encode()).hexdigest() print("Signature:\n {0}\n".format(signature)) signedRequest = request + "?" + parametersConcated + "&auth_signature=" + signature; print("SignedRequest:\n {0}\n".format(signedRequest))
Webpage: www.meridix.se
Email: support@meridix.se
Tel: +46 (0) 21 38 30 32