This example python 3 code shows how to fetch batch url metrics from Moz API with single request.
import time
import hmac
import base64
import urllib.request, urllib.parse, urllib.error
import json
import hashlib
accessID = "YourID"
secretKey = "YourKEY"
# Set your expires for several minutes into the future.
# Values excessively far in the future will not be honored by the Mozscape API.
expires = int(time.time() + 300)
# A new linefeed is necessary between your AccessID and Expires.
stringToSign = accessID+"\n"+str(expires)
# Get the "raw" or binary output of the hmac hash. below line single line
binarySignature = base64.b64encode(hmac.new(secretKey.encode(), stringToSign.encode(), hashlib.sha1).digest())
# We need to base64-encode it and then url-encode that.
urlSafeSignature = urllib.parse.quote_plus(binarySignature.decode('utf-8'))
# Add up all the bit flags you want returned.
# Learn more here: http://apiwiki.moz.com/url-metrics
cols = "68719476736"
# Put it all together and you get your request URL. below line single line
requestUrl = "http://lsapi.seomoz.com/linkscape/url-metrics/?Cols="+cols+"&AccessID="+accessID+"&Expires="+str(expires)+"&Signature="+urlSafeSignature
# Put your URLS into an array and json_encode them.
batchedDomains =['www.moz.com', 'www.apple.com', 'www.pizza.com']
jsonencoded = json.dumps(batchedDomains)
binary_data = jsonencoded.encode('utf-8')
req = urllib.request.Request(url=requestUrl, data=binary_data)
f = urllib.request.urlopen(req)
print(f.read().decode('utf-8'))
OUTPUT:
[{"pda":92.6779359634406},{"pda":100},{"pda":45.001317473850946}]