Yealink Forums

Full Version: RPS API - Authentication Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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);
friendly bump
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.
(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...
(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
(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)
Reference URL's