ForumCategory: QuestionsAuthentication Error
jleathlean asked 49 years ago

I’m trying to get data from the LiveEngagement Historical API.  The API key is setup and I’m able to connect and create the appropriate call – however it gives me a 401 – Authorization error. Here is the powershell that I’m attempting to use (found it from other threads on the forum).   cls hist
$oauth_consumer_key='<App Key>’
$oauth_consumer_secret=’<App Secret>’
$oauth_token=’<Access Token>’
$oauth_token_secret=’<Access Token Secret>’
$body=@{“ended”= ‘ true’ ; “start”= @{ “from” = 1538352000000; “to” = 1538438400000 } }
$oauth_nonce = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes([System.DateTime]::Now.Ticks.ToString()));
$ts = [System.DateTime]::UtcNow – [System.DateTime]::ParseExact(“01/01/1970″, “dd/MM/yyyy”, $null).ToUniversalTime();
$oauth_timestamp = [System.Convert]::ToInt64($ts.TotalSeconds).ToString();
$signature = “POST&”;
$signature += [System.Uri]::EscapeDataString( $url) + “&”;
$signature += [System.Uri]::EscapeDataString(“oauth_consumer_key=” + $oauth_consumer_key + “&”);
$signature += [System.Uri]::EscapeDataString(“oauth_nonce=” + $oauth_nonce + “&”);
$signature += [System.Uri]::EscapeDataString(“oauth_signature_method=HMAC-SHA1&”);
$signature += [System.Uri]::EscapeDataString(“oauth_timestamp=” + $oauth_timestamp + “&”);
$signature += [System.Uri]::EscapeDataString(“oauth_token=” + $oauth_token + “&”);
$signature += [System.Uri]::EscapeDataString(“oauth_version=1.0″); $signature_key = [System.Uri]::EscapeDataString($oauth_consumer_secret) + “&” + [System.Uri]::EscapeDataString($oauth_token_secret); $hmacsha1 = new-object System.Security.Cryptography.HMACSHA1;
$hmacsha1.Key = [System.Text.Encoding]::ASCII.GetBytes($signature_key);
$oauth_signature = [System.Convert]::ToBase64String($hmacsha1.ComputeHash([System.Text.Encoding]::ASCII.GetBytes($signature))); $oauth_authorization = ‘OAuth ‘;
$oauth_authorization += ‘oauth_consumer_key=”‘ + [System.Uri]::EscapeDataString($oauth_consumer_key) + ‘”,’;
$oauth_authorization += ‘oauth_nonce=”‘ + [System.Uri]::EscapeDataString($oauth_nonce) + ‘”,’;
$oauth_authorization += ‘oauth_signature=”‘ + [System.Uri]::EscapeDataString($oauth_signature) + ‘”,’;
$oauth_authorization += ‘oauth_signature_method=”HMAC-SHA1″,’
$oauth_authorization += ‘oauth_timestamp=”‘ + [System.Uri]::EscapeDataString($oauth_timestamp) + ‘”,’
$oauth_authorization += ‘oauth_token=”‘ + [System.Uri]::EscapeDataString($oauth_token) + ‘”,’;
$oauth_authorization += ‘oauth_version=”1.0″‘; $headers = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”
$headers.Add(“Authorization”, $oauth_authorization) $data=$body | ConvertTo-Json Invoke-restmethod -Method post -Uri $url -Body $data -Headers $headers -ContentType ‘application/json’  

5 Answers
Oren Katz Staff answered 11 months ago

What is your account number?
I suggest following the getting started part first to make sure you are using the right domain –

jleathlean answered 11 months ago

I did follow that – that’s how I got the URL to use for the POST.

Oren Katz Staff answered 11 months ago

Have you tried using Postman? I was able to use your account information to query the API.

Oren Katz Staff answered 11 months ago

I just tested it with ARC and it’s working for me as well, I took the generated Authorization from Postman so probably the one you are creating is incorrect.
P.S I enabled the option to upload more screenshots

jleathlean answered 11 months ago

Success 🙂
Using Postman – I figured out the issues…  I found the ‘Console’ in postman and that gave me better info than ARC on the failures.
1st – I was generating the signature using the Quoted oAuth Headers – apparently the quotes are only needed in the actual authorization header – for generating the signature they need to be excluded.
2nd – my timestamp was local time based – so even once I matched the signatures it was still failing.
I can now generate the calls in VB and it return the data.
Thanks for your assistance…

Oren Katz Staff replied 11 months ago

Great, happy to hear that it’s working now.