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>’
$url=”https://lo.enghist.liveperson.net/interaction_history/api/account/<AccountID>/interactions/search&#8221;
$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

Hey,
What is your account number?
I suggest following the getting started part first to make sure you are using the right domain – https://developers.liveperson.com/engagement-history-api-overview.html
Oren

jleathlean answered 11 months ago

Oren,
I did follow that – that’s how I got the URL to use for the POST.
http://api.liveperson.net/api/account/15853181/service/engHistDomain/baseURI.json?version=1.0
Result:

{"service":"engHistDomain","account":"15853181","baseURI":"lo.enghist.liveperson.net"}
Oren Katz Staff answered 11 months ago

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

Attachments
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

Attachments
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.