[#113] getBookings

Migrated from Redmine #113 | Author: Robert Hamilton
Status: Resolved | Priority: Normal | Created: 2018-02-19


I’ve been working hard on getting the API to work with VB and I’ve made some significant progress.

I realize you don’t have any code examples for VB and I suppose posting my code wouldn’t be of much help. But I’ve managed to get the token and I’ve managed to get the getEventsList method to work.

For some reason when I use a similar approach to using the getBookings method I’m denied. I just used getBookings but I didn’t pass any parameters so I had expected to get a listing of bookings. Instead I get this response:

{“error”:{“code”:-32600,“message”:“Access denied”,“data”:null},“id”:“4”,“jsonrpc”:“2.0”}

Same thing when I pass start_date and other parameters - always denied.

I realize that I need to use https://user-api.simplybook.me/admin for getBookings instead of https://user-api.simplybook.me but other than that, is there anything else I need to do differently between getEventslist and getBookings? Like use your secret token or get a new token with your user name and password or something?

Any ideas where I could go from here to track down the problem?

Robert Hamilton wrote:

So to clarify, when I’m trying to use getBookings do I use:

https://user-api.simplybook.me/admin

“X-Company-Login”, “MyCompanyHere”
“X-Token”, ??? <=== what goes here? User token or company token?

I get denied with either token but this is very confusing for a new user…

Redmine Admin wrote:

Please follow this instructions API documentation | SimplyBook.me Online Scheduling

Robert Hamilton wrote:

Ok if you aren’t serious about actually offering real support it’s clear I can’t do business with your company. Too bad because I could have brought you hundreds of new customers. If you change your mind and decide to get serioius and really support your customers - more than just pasting a link to your api - please get back to me.

Dmytro Bondarev wrote:

Hi, Robert! To use API it is required to read documentation.
Mike sent you link where you can read what you need to send in “Authorization” section Screenshot by Lightshot
So first you need to get token by your company login and API key and then pass this token.

Robert Hamilton wrote:

I’ll repeat my question because I don’t think you read it:

I got my company token.
I passed my company token to getEventsList.
It worked - I got my events list.
I past the same token to getBookings.
I got a Denied message.

So I got and tried my user token.
I got a denied message with getBookings.

So I posted this question and you said I should read the API documentation - which wasn’t at all helpful. I have memorized your API documentation by this point. I can probably type it out from memory. Any OTHER ideas?

Redmine Admin wrote:

getBookings is administrative method while getEventsList is public.

Dmytro Bondarev wrote:

Hi, Robert! getBookings is method from administrative service.
To use this method you need to get admin token and pass it to headers. Mike sent you link with documentation how to do this.

Robert Hamilton wrote:

Yes, I know. I did that. I got a denied message.

In my post above I called it my “user token” rather than my admin token but that’s the method I used to get it.

As I said, when I used the admin token I got a Denied message.

I see you have an API explorer for https://user-api.simplybook.me but you don’t have one for https://user-api.simplybook.me/admin that I can find. Do you have any other ideas?

Dmytro Bondarev wrote:

Please provide raw http request (with headers and body).

Robert Hamilton wrote:

This is the public company token I received:

3e0c5d8164866ec3692b831dddc82c2302823b606f3a922d6792ae49d4938622

This is the Admin token I received:
cda265f9f9474c577cdd5bc95c1fbc34ca9bc3183d932952da62eaaacc4e522b

I realize the tokens change for each session but I wanted to show you that I do have the two tokens.

I know you don’t have VB code but this is the code I used:

’ URL = https://user-api.simplybook.me/admin
’ MethodName$ = getBookings
’ params is null
’ glbCompanyLogin = (my company)
’ glbUserToken = admin token

@Public Function JSONRPC(URL$, MethodName$, ParamArray Params()) As String
Static id As Currency: id = id + 1
Dim http As New WinHttp.WinHttpRequest, JSONBody As cCollection, JSONParams As cCollection, P
http.Open “POST”, URL, False
http.SetRequestHeader “Content-Type”, “application/json; charset=UTF-8”
http.SetRequestHeader “Accept”, “application/json”

If Len(glbCompanyLogin) Then
http.SetRequestHeader “X-Company-Login”, glbCompanyLogin
End If

If Len(glbToken) Then
http.SetRequestHeader “X-Token”, glbuserToken
End If

Set JSONParams = New_c.JSONArray

For Each P In Params
JSONParams.Add P
Next P

Set JSONBody = New_c.JSONObject
JSONBody.Prop(“jsonrpc”) = “2.0”
JSONBody.Prop(“method”) = MethodName
JSONBody.Prop(“id”) = id
JSONBody.Prop(“params”) = JSONParams

http.Send JSONBody.SerializeToJSONUTF8
JSONRPC = http.ResponseText
End Function@

result: {“error”:{“code”:-32600,“message”:“Access denied”,“data”:null},“id”:“7”,“jsonrpc”:“2.0”}

Dmytro Bondarev wrote:

Ok, i see you pass
http.SetRequestHeader “X-Token”, glbuserToken

but in documentation X-User-Token for admin API.
please replace to

http.SetRequestHeader “X-User-Token”, glbuserToken

Robert Hamilton wrote:

That’s huge progress! Now I am getting a message:

{“error”:{“code”:-32011,“message”:“Params is not array”,“data”:},“id”:“7”,“jsonrpc”:“2.0”}

I thought you could pass a blank or null list of params and just get a dump of all events?

I tried passing:

@
Set getBookings = New_c.JSONDecodeToCollection(JSONRPC(EndPoint, “getBookings”, “date_from”, “2017-01-01”, “date_to”, “2018-02-20”))
@

I still got back a response:

{“error”:{“code”:-32011,“message”:“Params is not array”,“data”:},“id”:“7”,“jsonrpc”:“2.0”}

I’m afraid I don’t know how to get the raw http request to send to you.

Dmytro Bondarev wrote:

Hi! Please provide http request.
It could be just json body.

Robert Hamilton wrote:

Ok finally got it working! The key is to bundle up all the parameters and pass them as one long string surrounded by {} in the body. Feel free to mark this resolved.