[#252] APi integration problems

Migrated from Redmine #252 | Author: David Saenz
Status: New | Priority: High, I’m very impatient | Created: 2018-10-09


Hello,
I am trying to integrate the system through the API and using the example of the web, I have errors just to start.

I’m following the steps on this page

Specifically the code that I am testing is this:

var loginClient = new JSONRpcClient ({
   'url': 'https://user-api.simplybook.me' + '/ login',
   'onerror': function (error) {},
});

var token = loginClient.getToken (YOUR_COMPANY_LOGIN, YOUR_API_KEY);

The first line, where I do the “new JSONRpcClient”, does not give errors.
It is in the second line that you can not find the function or method “getToken ()”.

As recommended by the page, I am using this file:
https://simplybook.me/api_example/json-rpc-client.js

But in this file I do not see the getToken method.

Could you help me with this?

Thanks in advance!
David.

Redmine Admin wrote:

Please provide raw http request to investigate

David Saenz wrote:

Hi,
sorry, I had an error in my code.
Now getToken works, but I have an error.

I’ll try to solve the error, if I do not, I’ll let you know.

Thanks!

David Saenz wrote:

Hi,
I can’t solve the problem

This is my code

const _ = this
var loginClient = new JSONRpcClient({
     'url': 'https://user-api.simplybook.me/login',
     'onerror': function (error) {
           console.error("Error", error)
     }
});

var token = loginClient.getToken(_.opts.company, _.opts.publicApiKey);

When I launh this code, I have 3 request to https://user-api.simplybook.me/login on network tab.
I attach the raw reponse in this post.

For me is extrange three call.
I have reviewed the object code ‘JSONRpcClient’ and I only see two ajax calls in the init method.
In any case, could you tell me what this error refers to?

Thanks in advance.

David

David Saenz wrote:

I think the file attached fails.
I add a zip now.

David Saenz wrote:

David Saenz wrote:

I think the file attached fails.
I add a zip now.

You can see attach files?
I can’t.

Redmine Admin wrote:

please just provide us raw http request as plain text, nothing else is needed to solve any API problem

David Saenz wrote:

I attach in different formats in previous comments.
Maybe your file upload system don’t work.

First call
{“transport”:“POST”,“envelope”:“JSON-RPC-2.0”,“contentType”:“application/json”,“SMDVersion”:“2.0”,“target”:“/login”,“services”:{“getServiceUrl”:{“envelope”:“JSON-RPC-2.0”,“transport”:“POST”,“parameters”:[{“type”:“object”,“name”:“companyLogin”,“optional”:false}],“returns”:“object”},“getToken”:{“envelope”:“JSON-RPC-2.0”,“transport”:“POST”,“parameters”:[{“type”:“object”,“name”:“companyLogin”,“optional”:false},{“type”:“object”,“name”:“apiKey”,“optional”:false}],“returns”:“object”},“getUserToken”:{“envelope”:“JSON-RPC-2.0”,“transport”:“POST”,“parameters”:[{“type”:“object”,“name”:“companyLogin”,“optional”:false},{“type”:“object”,“name”:“userLogin”,“optional”:false},{“type”:“object”,“name”:“userPassword”,“optional”:false}],“returns”:“object”},“getApplicationToken”:{“envelope”:“JSON-RPC-2.0”,“transport”:“POST”,“parameters”:[{“type”:“object”,“name”:“applicationApiKey”,“optional”:false}],“returns”:“object”}},“methods”:{“getServiceUrl”:{“envelope”:“JSON-RPC-2.0”,“transport”:“POST”,“parameters”:[{“type”:“object”,“name”:“companyLogin”,“optional”:false}],“returns”:“object”},“getToken”:{“envelope”:“JSON-RPC-2.0”,“transport”:“POST”,“parameters”:[{“type”:“object”,“name”:“companyLogin”,“optional”:false},{“type”:“object”,“name”:“apiKey”,“optional”:false}],“returns”:“object”},“getUserToken”:{“envelope”:“JSON-RPC-2.0”,“transport”:“POST”,“parameters”:[{“type”:“object”,“name”:“companyLogin”,“optional”:false},{“type”:“object”,“name”:“userLogin”,“optional”:false},{“type”:“object”,“name”:“userPassword”,“optional”:false}],“returns”:“object”},“getApplicationToken”:{“envelope”:“JSON-RPC-2.0”,“transport”:“POST”,“parameters”:[{“type”:“object”,“name”:“applicationApiKey”,“optional”:false}],“returns”:“object”}}}

Second call
{“error”:{“code”:-32600,“message”:“Invalid Request”,“data”:null},“id”:null}

Third call
{“error”:{“code”:-32000,“message”:“No entry is registered for key ‘dbname’”,“data”:null},“id”:“1”,“jsonrpc”:“2.0”}

Redmine Admin wrote:

it is responses, not requests.

David Saenz wrote:

First request headers

Provisional headers are shown
Accept: */*
Origin: http://dev.etronroom:3000
Referer: http://dev.etronroom:3000/booking
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36

Second request headers

Provisional headers are shown
Access-Control-Request-Headers: content-type
Access-Control-Request-Method: POST
Origin: http://dev.etronroom:3000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36

Third request headers

Provisional headers are shown
Accept: application/json, text/javascript, */*; q=0.01
Content-Type: application/json
Origin: http://dev.etronroom:3000
Referer: http://dev.etronroom:3000/booking
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36

Third request payload

{jsonrpc: "2.0", method: "getToken",…}
id: 1
jsonrpc: "2.0"
method: "getToken"
params: [null, "17011f0d1a814cd929ba707a5d59c9ab388d42eefd50af6f6f616570496260cf"]
0: null
1: "17011f0d1a814cd929ba707a5d59c9ab388d42eefd50af6f6f616570496260cf"

Thanks

Redmine Admin wrote:

please go trough our API explore API documentation | SimplyBook.me Online Scheduling and take a look at HTTP Request tab

David Saenz wrote:

Ok, i have the error, the login compnay is null.
Sorry for my istakes.

Redmine Admin wrote:

params: [null, "17011f0d1a814cd929ba707a5d59c9ab388d42eefd50af6f6f616570496260cf"] it should be company login instead null