Skip to content

Instantly share code, notes, and snippets.

@compnski
Created November 19, 2015 19:23
Show Gist options
  • Save compnski/fdeab1f5e02fed0fbc57 to your computer and use it in GitHub Desktop.
Save compnski/fdeab1f5e02fed0fbc57 to your computer and use it in GitHub Desktop.
Please update with customers submitted versions or ones we create inhouse.
PHP (from dan@ufn)
p_api_key = 'YOUR_API_KEY';
$filter_json = '{
"dashboard": 8227,
"embed": true,
"filters": [{"name": "AccountIDs", "value": "71005"}]
}';
$encode_json = urlencode(str_replace(' ','',$filter_json));
$path_to_hex = '/api/embedded_dashboard?data='.$encode_json;
// false in param 4 outputs hex
$hex_key_sig = hash_hmac('sha256', $path_to_hex, $p_api_key, FALSE);
$embed_query = 'https://www.periscopedata.com/api/embedded_dashboard?data='.$encode_json.'&signature='.$hex_key_sig;
print_r($embed_query);
C#
using System.Security.Cryptography;
using System.Text;
public class Placeholder {
public static void Main() {
var encoding = new System.Text.ASCIIEncoding();
string apiKey = // YOUR KEY HERE
string encodedJsonBlob = "%7B%20%22dashboard%22:%207503,%20%22embed%22:%20true,%20%22filters%22:%20%5B%7B%22name%22:%20%22BrandFilter%22,%20%22value%22:%20%22M812_USACA_ECBE44%22%7D%5D%20%7D"; // Replace with real encoding logic!
string fullPath = "/api/embedded_dashboard?data=" + encodedJsonBlob;
HMACSHA256 hmac = new HMACSHA256(encoding.GetBytes(apiKey));
byte[] hashMessage = hmac.ComputeHash(encoding.GetBytes(fullPath));
StringBuilder builder = new StringBuilder();
for (int i = 0; i < hashMessage.Length; i++) {
builder.Append(hashMessage[i].ToString("x2"));
}
string signature = builder.ToString();
string fullURL = "https://www.periscopedata.com" + fullPath + "&signature=" + signature;
}
}
JavaScript
api_key = # YOUR KEY HERE
encoded_json_blob = "%7B%20%22dashboard%22:%207503,%20%22embed%22:%20true,%20%22filters%22:%20%5B%7B%22name%22:%20%22BrandFilter%22,%20%22value%22:%20%22M812_USACA_ECBE44%22%7D%5D%20%7D" # replace with real encoding logic!
fullpath = '/api/embedded_dashboard?data=' + encoded_json_blob
signature = require('crypto').createHmac('sha256', api_key).update(fullpath).digest('hex')
full_url = 'https://www.periscopedata.com' + fullpath + '&signature=' + signature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment