[#1124] Create bookings from API

Migrated from Redmine #1124 | Author: Luis Solana
Status: New | Priority: Normal | Created: 2023-10-27


Good afternoon,

I am new to API usage, and particular at Simplybook’s. I am having trouble creating a booking from the admin side. I attatch here the code.

The error is:

Uncaught ReferenceError: instance is not defined
onerror file:///C:/Users/lsolana/Desktop/DATA TASAP/Software/TASAP_Bookings_a1/js/query.js:26
success file:///C:/Users/lsolana/Desktop/DATA TASAP/Software/TASAP_Bookings_a1/js/json-rpc-client.js:100
jQuery 6
method file:///C:/Users/lsolana/Desktop/DATA TASAP/Software/TASAP_Bookings_a1/js/json-rpc-client.js:88
file:///C:/Users/lsolana/Desktop/DATA TASAP/Software/TASAP_Bookings_a1/js/query.js:70
jQuery 8

Thanks in advance.

Luis Solana wrote:

jQuery(document).ready(function () {

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

client = null,


$company = "COMPANY";
$user = "USER"; //Fill in this data. Name of the account: email
$pass = "PASS"; //Fill in this data. Password

var token = loginClient.getUserToken($company, $user, $pass);
this.client = new JSONRpcClient({
	'url': 'https://user-api.simplybook.me' + '/admin/',
	'headers': {
		'X-Company-Login': $company,
		'X-User-Token': token
	},
	'onerror': function (error) {
		instance.error(error);
	}
});

// Booking trial (Danger)

$additionalFieldsActivated = this.client.isPluginActivated('event_field');
//console.log($additionalFieldsActivated); // FALSE

//$additionalFields = this.client.getAdditionalFields();
$additionalFields = {};

//console.log($additionalFields);



//console.log($additional);

var eventId = 170;
var unitId = 35; // Luis Solana unit (provider) code
var date = "2023-12-12";
var time = "11:11:11";
var clientData = {
	'id': 293,
	'name': "Luis" + " " + "Solana",
	'email': "EMAIL",
	'phone': "+34XXXXXXXXX",
};
//$clientData = 293;

console.log(clientData);

$booking = new Object();
$booking = this.client.book(eventId, unitId, date, time, clientData, $additionalFields);
console.log($booking);
// Logs

$servicesList = this.client.getCategoriesList();
$clientList = this.client.getClientList();
$unitList = this.client.getUnitList();
$eventList = this.client.getEventList();
//console.log($clientList);

});

Redmine Admin wrote:

please provide raw http request and response

Luis Solana wrote:

Please, as I told I am new to programming. Where can I specifically find the http request?

Luis Solana wrote:


{
  "log": {
    "version": "1.2",
    "creator": {
      "name": "Firefox",
      "version": "115.4.0"
    },
    "browser": {
      "name": "Firefox",
      "version": "115.4.0"
    },
    "pages": [
      {
        "id": "page_1",
        "pageTimings": {
          "onContentLoad": -5932,
          "onLoad": 7
        },
        "startedDateTime": "2023-10-27T16:21:38.599+02:00",
        "title": "Prueba 1"
      }
    ],
    "entries": [
      {
        "startedDateTime": "2023-10-27T16:21:38.599+02:00",
        "request": {
          "bodySize": 0,
          "method": "POST",
          "url": "https://user-api.simplybook.me/admin/",
          "httpVersion": "",
          "headers": [
            {
              "name": "Host",
              "value": "user-api.simplybook.me"
            },
            {
              "name": "User-Agent",
              "value": "Mozilla/5.0 (Windows NT 6.1; rv:109.0) Gecko/20100101 Firefox/115.0"
            },
            {
              "name": "Accept",
              "value": "application/json, text/javascript, */*; q=0.01"
            },
            {
              "name": "Accept-Language",
              "value": "sr-RS,sr;q=0.8,en-US;q=0.5,en;q=0.3"
            },
            {
              "name": "Accept-Encoding",
              "value": "gzip, deflate, br"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "X-Company-Login",
              "value": "tutorasap"
            },
            {
              "name": "X-User-Token",
              "value": "b9888f1eb4d3761b289509cbc6751a9b735d9fa0c42af09a8a901ac038698054"
            },
            {
              "name": "Content-Length",
              "value": "60"
            },
            {
              "name": "Origin",
              "value": "null"
            },
            {
              "name": "Connection",
              "value": "keep-alive"
            },
            {
              "name": "Sec-Fetch-Dest",
              "value": "empty"
            },
            {
              "name": "Sec-Fetch-Mode",
              "value": "cors"
            },
            {
              "name": "Sec-Fetch-Site",
              "value": "cross-site"
            }
          ],
          "cookies": [],
          "queryString": [],
          "headersSize": 0
        },
        "response": {
          "status": 0,
          "statusText": "",
          "httpVersion": "",
          "headers": [],
          "cookies": [],
          "content": {},
          "redirectURL": "",
          "headersSize": 0,
          "bodySize": -1
        },
        "cache": {},
        "timings": {
          "blocked": 0,
          "dns": 0,
          "connect": 0,
          "ssl": 0,
          "send": 0,
          "wait": 0,
          "receive": 0
        },
        "time": 0,
        "pageref": "page_1"
      }
    ]
  }
}