[#263] Help on how to start testing API

Migrated from Redmine #263 | Author: Michael Oosthuizen
Status: New | Priority: High, I’m very impatient | Created: 2018-10-21


Hello! I have experience with HTML, CSS, JS, Python and C#, but I’ve never worked with back-end or server-side code before.

I want to start testing the SimplyBook API with the eventual goal of implementing it on our own website with a more user-friendly interface for multiple bookings.

I’ve read through the API guide, explorer, and docs. I’ve downloaded the html, css, and js files of the API example and read through them. But the one thing I can’t figure out is how to start testing the API!

I’ve tried saving the API example files (downloaded all the files - including .css and .js - from the source of Simplybook.me API example) and opening the index.html in my web browser. I’ve tried hosting the files via FileZilla - where I host my current, unrelated website. I’ve tried locally hosting the files with MAMP. And finally, I’ve tried to host them locally with Node.js. Note: I’ve tried right-click → Save Page As…, and I’ve tried right-click → View Source, as the html files differ depending on which method you use.

However, the website is unable to replicate the example project. No matter what I do, my copied website does not look like it’s fetching data from the SimplyBook API. For example, the start times won’t show like they do on the actual API example.

If somebody could please urgently point me in the right direction to start off, I’d be extremely grateful. How can I test the API on a locally hosted server on my computer? I feel like there is one vital piece of info I’m missing, because the API documentation is very clear to me, I just have no idea where or how to start using it..

Thank you in advance, and sorry if this is a very basic question.

Michael Oosthuizen wrote:

Sorry, internet connection is slow and apparently I double-posted this. Not sure ow to delete my issue, please see my post in the “Support” section.

Redmine Admin wrote:

Hi,

You can check API Explorer code and reproduce it on your site.
We also have working php example, you can check it here GitHub - vetalsimplybook/simplybook_callback_example_php

Michael Oosthuizen wrote:

Is it possible to successfully reproduce the code on a locally-hosted test site at, for example, 127.0.0.1:3000? I checked the console in Firefox and it is giving a Cross-Origin Request Blocked for the API website whwnever I try to call an API method.

Michael Oosthuizen wrote:

I’ve just tested, using a plain html file with only the following code (taken from Step 1 of the API Exlorer):
var loginClient = new JSONRpcClient({
‘url’: ‘//user-api.simplybook.me/login’,
‘onerror’: function (error) {
alert(error);
}
});
var token = loginClient.getToken(‘mib’, ‘f43618e37b82004066d60db3431f4a06392599a6cfcafa8268bf25becc0ec7d7’);

The exact error in Firefox’s console reads: “Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://user-api.simplybook.me/login. (Reason: CORS header ‘Access-Control-Allow-Origin’ does not match ‘http://127.0.0.1:3000’)”

Michael Oosthuizen wrote:

When I insert the script onto my existing web page, the console error reads: :Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://user-api.simplybook.me/login. (Reason: CORS request external redirect not allowed)."

Redmine Admin wrote:

Please read this CORS errors - HTTP | MDN
It seems you need to play with browser settings