Yealink Forums
RPS API - Authentication Error - Printable Version

+- Yealink Forums (http://forum.yealink.com/forum)
+-- Forum: IP Phone Series (/forumdisplay.php?fid=4)
+--- Forum: Auto Provisioning (/forumdisplay.php?fid=14)
+--- Thread: RPS API - Authentication Error (/showthread.php?tid=43444)



RPS API - Authentication Error - jrmende5 - 11-22-2019 12:08 AM

Good day.

I am working on connecting to the RPS API using the new version (REST server using Access Key and Access Key Secret) from POSTMAN.

But I receive the error: 401 - signature.invalid

I attach the code in postman (Pre-request script):

function getTimestp(){
dt = new Date();
return dt.getTime();
}

function getNonce(){
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + s4() + s4() + s4() + s4() + s4() + s4();
}


xkey = "AccessKey";
xsecret = "SecretKey";
xtimest = getTimestp();
xnonce = getNonce();

xheaders = "X-Ca-Key:"+xkey+"\n"+"X-Ca-Nonce:"+xnonce+"\n"+"X-Ca-Timestamp:"+xtimest;

param = pm.request.body.formdata;
dp = Object.values(param);
lg = dp[0];

stparam = "";

for(i=0;i<lg.length;i++){
aPam = lg[i];

equal = "=";
if(aPam["value"] === ""){
equal = "";
}

if(i+1 == lg.length){
stparam += aPam["key"]+equal+aPam["value"];
}else{
stparam += aPam["key"]+equal+aPam["value"]+"&";
}
}


stringToSign = "POST\n"+xheaders+"\n"+pm.request.url.getPath()+"\n"+stparam;

signatureutf8 = CryptoJS.enc.Utf8.parse(stringToSign);
secretByteArray = CryptoJS.enc.Utf8.parse(xsecret);
signatureBytes = CryptoJS.HmacSHA256(signatureutf8,secretByteArray);
requestSignatureBase64String = CryptoJS.enc.Base64.stringify(signatureBytes);

pm.environment.set("signature",requestSignatureBase64String);



RE: RPS API - Authentication Error - jrmende5 - 11-26-2019 08:02 PM

friendly bump


RE: RPS API - Authentication Error - complex1 - 11-28-2019 11:24 AM

Hi,

I can’t really help you on this, but may I suggest to submit a ticket to support?
https://ticket.yealink.com/

Hope this will help.


RE: RPS API - Authentication Error - bmueller - 01-06-2020 02:35 PM

(11-22-2019 12:08 AM)jrmende5 Wrote:  Good day.

I am working on connecting to the RPS API using the new version (REST server using Access Key and Access Key Secret) from POSTMAN.

But I receive the error: 401 - signature.invalid

I attach the code in postman (Pre-request script):

function getTimestp(){
dt = new Date();
return dt.getTime();
}

function getNonce(){
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + s4() + s4() + s4() + s4() + s4() + s4();
}


xkey = "AccessKey";
xsecret = "SecretKey";
xtimest = getTimestp();
xnonce = getNonce();

xheaders = "X-Ca-Key:"+xkey+"\n"+"X-Ca-Nonce:"+xnonce+"\n"+"X-Ca-Timestamp:"+xtimest;

param = pm.request.body.formdata;
dp = Object.values(param);
lg = dp[0];

stparam = "";

for(i=0;i<lg.length;i++){
aPam = lg[i];

equal = "=";
if(aPam["value"] === ""){
equal = "";
}

if(i+1 == lg.length){
stparam += aPam["key"]+equal+aPam["value"];
}else{
stparam += aPam["key"]+equal+aPam["value"]+"&";
}
}


stringToSign = "POST\n"+xheaders+"\n"+pm.request.url.getPath()+"\n"+stparam;

signatureutf8 = CryptoJS.enc.Utf8.parse(stringToSign);
secretByteArray = CryptoJS.enc.Utf8.parse(xsecret);
signatureBytes = CryptoJS.HmacSHA256(signatureutf8,secretByteArray);
requestSignatureBase64String = CryptoJS.enc.Base64.stringify(signatureBytes);

pm.environment.set("signature",requestSignatureBase64String);

Did you ever get this solved? I am having the same issues...


RE: RPS API - Authentication Error - TeleCloud - 03-13-2020 06:01 AM

(01-06-2020 02:35 PM)bmueller Wrote:  
(11-22-2019 12:08 AM)jrmende5 Wrote:  Good day.

I am working on connecting to the RPS API using the new version (REST server using Access Key and Access Key Secret) from POSTMAN.

But I receive the error: 401 - signature.invalid

I attach the code in postman (Pre-request script):

function getTimestp(){
dt = new Date();
return dt.getTime();
}

function getNonce(){
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + s4() + s4() + s4() + s4() + s4() + s4();
}


xkey = "AccessKey";
xsecret = "SecretKey";
xtimest = getTimestp();
xnonce = getNonce();

xheaders = "X-Ca-Key:"+xkey+"\n"+"X-Ca-Nonce:"+xnonce+"\n"+"X-Ca-Timestamp:"+xtimest;

param = pm.request.body.formdata;
dp = Object.values(param);
lg = dp[0];

stparam = "";

for(i=0;i<lg.length;i++){
aPam = lg[i];

equal = "=";
if(aPam["value"] === ""){
equal = "";
}

if(i+1 == lg.length){
stparam += aPam["key"]+equal+aPam["value"];
}else{
stparam += aPam["key"]+equal+aPam["value"]+"&";
}
}


stringToSign = "POST\n"+xheaders+"\n"+pm.request.url.getPath()+"\n"+stparam;

signatureutf8 = CryptoJS.enc.Utf8.parse(stringToSign);
secretByteArray = CryptoJS.enc.Utf8.parse(xsecret);
signatureBytes = CryptoJS.HmacSHA256(signatureutf8,secretByteArray);
requestSignatureBase64String = CryptoJS.enc.Base64.stringify(signatureBytes);

pm.environment.set("signature",requestSignatureBase64String);

Did you ever get this solved? I am having the same issues...

Anyone get this working?
can we please have some sample code.
Thanks


RE: RPS API - Authentication Error - wecloudit - 11-26-2020 04:53 PM

(03-13-2020 06:01 AM)TeleCloud Wrote:  
(01-06-2020 02:35 PM)bmueller Wrote:  
(11-22-2019 12:08 AM)jrmende5 Wrote:  Good day.

I am working on connecting to the RPS API using the new version (REST server using Access Key and Access Key Secret) from POSTMAN.

But I receive the error: 401 - signature.invalid

I attach the code in postman (Pre-request script):

function getTimestp(){
dt = new Date();
return dt.getTime();
}

function getNonce(){
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + s4() + s4() + s4() + s4() + s4() + s4();
}


xkey = "AccessKey";
xsecret = "SecretKey";
xtimest = getTimestp();
xnonce = getNonce();

xheaders = "X-Ca-Key:"+xkey+"\n"+"X-Ca-Nonce:"+xnonce+"\n"+"X-Ca-Timestamp:"+xtimest;

param = pm.request.body.formdata;
dp = Object.values(param);
lg = dp[0];

stparam = "";

for(i=0;i<lg.length;i++){
aPam = lg[i];

equal = "=";
if(aPam["value"] === ""){
equal = "";
}

if(i+1 == lg.length){
stparam += aPam["key"]+equal+aPam["value"];
}else{
stparam += aPam["key"]+equal+aPam["value"]+"&";
}
}


stringToSign = "POST\n"+xheaders+"\n"+pm.request.url.getPath()+"\n"+stparam;

signatureutf8 = CryptoJS.enc.Utf8.parse(stringToSign);
secretByteArray = CryptoJS.enc.Utf8.parse(xsecret);
signatureBytes = CryptoJS.HmacSHA256(signatureutf8,secretByteArray);
requestSignatureBase64String = CryptoJS.enc.Base64.stringify(signatureBytes);

pm.environment.set("signature",requestSignatureBase64String);

Did you ever get this solved? I am having the same issues...

Anyone get this working?
can we please have some sample code.
Thanks

We got a working PHP solution: pm me for details (will send the code)