[#148] -32600 Access Denied Error

Migrated from Redmine #148 | Author: Anonymous
Status: Rejected | Priority: Normal | Created: 2018-04-10


I keep running into the -32600 “Access Denied” error. I try getting a new token and it still has the -32600 error.
The token expires after one hour then when I try to access some services they work and some don’t.

Not sure if you have any pointers.

Thanks!! (Here’s my SBM API init code)

import { sbm, JSONRpcClient } from ‘./sbmConfig’;

let SBM = {
client: null
}

const companyLogin = ‘cyno’;
const sbmApiKey = sbm.apiKey;
let tokenExpired = null;

const getToken = () => {
let loginClient = getLoginClient();
return loginClient.getToken(companyLogin, sbmApiKey);
}

const getSbmClient = (cb = null) => {
// console.log(‘Getting SBM client.’);
SBM.client = getJSONRpcClient(cb);

if (!SBM.client) {
    // This doesn't work
    SBM.client = getJSONRpcClient(cb);
    console.log('Token Expired: Getting new token.', );
} else {
    return SBM.client;
}

}

const getAsyncSbmClient = ({refreshTokenCallback, stopAutoRefresh}) => {
// console.log(‘Getting Async SMB RPC Client’);
return new Promise(function(resolve, reject) {
SBM.client = getJSONRpcClient();

    if (SBM.client) {
        resolve(SBM.client);
        console.log('SBM client has been obtained: ', SBM.client);
        return;
    }
    let autoRefresh;
    if (!stopAutoRefresh) {
        autoRefresh = setInterval(
            () => {
                const sbmClient = getJSONRpcClient(); 
                refreshTokenCallback(sbmClient);
                resolve(sbmClient);
            }, 3480000
        );
    } else {
        clearInterval(autoRefresh);
    }
});

}

// LOGIN TO SBM
const getLoginClient = () => {
return new JSONRpcClient({
url: ‘//user-api.simplybook.me/login’,
onerror: function (error) {
alert(error);
console.log(‘Client Login Error @Calendar Actions’);
},
onsuccess: function (result) {
// alert(result);
// console.log(result);
console.log(‘SBM Client Login Successful!’);
}
});
}

const getJSONRpcClient = (cb = null) => {
let token = getToken();
return new JSONRpcClient({
‘url’: ‘//user-api.simplybook.me’,
‘headers’: {
‘X-Company-Login’: companyLogin,
‘X-Token’: token
},
‘onerror’: function (error) {
alert(‘Error: ‘+ error + ’ Message: ’ + error.message + ’ Code: ’ + error.code + ’ Token: ’ + token);
console.log(’%cGETTING CLIENT ERROR @SBM Calendar Actions’,‘color: greenyellow’);
if (error.code == -32600){
// tokenExpired = true;
// let newLoginClient = getLoginClient();
let newToken = getToken();
SBM.client = new JSONRpcClient({
‘url’: ‘//user-api.simplybook.me’,
‘headers’: {
‘X-Company-Login’: companyLogin,
‘X-Token’: newToken
},
‘onerror’: function (error) {
alert('Repeat Error: ‘+ error + ’ Message: ’ + error.message + ’ was fired from repeat call to sbmLogin ’ + ‘Code: ’ + error.code + ’ Token: ’ + newToken);
console.log(’%cGETTING CLIENT ERROR @SBM Calendar Actions’,‘color: greenyellow’);
},
‘onsuccess’: (result) => {
console.log(‘successfully logged in this time’);
}
});
cb(SBM.client);
}
}
});
}

export {getSbmClient as default, getAsyncSbmClient};

Redmine Admin wrote:

Unfortunately it is very hard for us to check witch part of your code cause this problems. Please provide us raw http request. Will check if there is some problems

Anonymous wrote:

How would you recommend refreshing the token after expiry? How do you usually deal with this issue? Thanks.

Redmine Admin wrote:

you should generatenew token once you got expiration error