SambaPOS API Integration with NewBook PMS/Booking System


#124

I am still not following you…how would that be a variable? What would it do?


#125

OK I think I see what your saying.


#126

im trying to use a simplified value in the call to specify the json key return?

bookingdetails('xxxxx',pax)

into

function bookingdetails(sitename,detail)

where detail of pax variable is then used in the

 var pax = 'booking_adults';

 return responseObject.+detail;

to return the number of adults for example.


#127

it would still need to be ‘pax’


#128

I think we should stop for now and talk about what your doing with sambapos so it makes more sense. You have an idea what your doing but all we can see is your script. So it takes us a bit to understand what your doing. AKA how your using the script.

It helps to show your entire process that you are doing or want to do. We have no clue how your entities are setup :stuck_out_tongue: Or how your using them.


#129

Am seting scripts in order to pull the data from the return into the entity data fields for that room entity.

Rather than have a script for each detail wanted to pull will define the response key in the call in the entity data field.

Haven’t got that far myself, am testing out the scripts . :slight_smile:


#130

Remember we have no clue how your using it. I have an idea but really not sure until you show that.


#131

This help for a start?


#132

I was trying to specify the return responseObject. from the script call to save having what will be dozens of individual scripts for each detail wanting to be pulled by time finnished.


#133

Ok it sounds like you have a nice grasp on it. I will leave you to it. If you run into issues holler.


#134
responseObject.+detail

I do not think that will work. This is not just a matter of concatenating strings. You are working with an Object. True Objects will have properties and/or methods. In your case, the “detail” is a property of the object. So unfortunately, you will need to pick them all out of the Object 1-by-1 … you won’t be able to make that call to a property dynamically.

Also, quite likely, you should be looking at responseObject[0].something as @kendash showed earlier on. This is because the Object in this case is also an Array, and you want the first element of that Array, which is element 0.

I still don’t understand your flow, but basically, you could do this…

function bookingdetails(sitename,detail) {
  if (detail=='pax') {
    return responseObject[0].booking_adults;
  }
  else if (detail=='blah') {
    return responseObject[0].blah_field;
  }
}

… or something to that effect.


#135

That would be the solution if I went that way :slight_smile: thanks.

I did pick up on that but the main source url im working with at the minute is onle a single entry/not an array, the site list was bit by sending the stitename to the booking url its returning the infor for that rooms booking rather than a list of all the sites/bookings in a big list where aray selecting is needed.

There is a guest name aray as they allow multiple guests per room by looks of it but not got that far :smile:

I imagine it would end up looking like return responseObject.guests[0].firstname;
The responce is formatted like this;

"guests": [
                 {
                    "firstname": "John",

So would it be;
return responseObject.guests[0].firstname;
or
return responseObject.guests.[0]firstname;


#136

From looking at their json some are arrays some are not. The example I gave was an array even though it was simple.


#137

The site_inhouse_booking url gives a single main array but the guests ‘key’ has a sub array if thats the right term, as possible to have multiple guests within a a room response.


#138

In general, best practice is to gather as much data in a single call as you can, then parse it all out of the returned JSON, rather than hitting their site/api multiple times with smaller detailed calls.

So you should try your best to gather all data for an Entity once, in one big chunk, then go about updating the Entity data using the SambaPOS API. Do this rather than putting a {CALL:X} in each Entity data field.

Some quick SambaPOS API documentation…
http://forum.sambapos.com/t/quick-js-api-documentation/4923

From the above link, it looks like you would use this:

api.Entity(name).Data(name).Update(value);

So, you would handle the Event for Entity Selected, or Ticket Entity Changed, and call your “do it all” script in an Action (ie. Execute Script Action) inside that Rule.


P.S…

The first one would be correct… the second one is not valid syntax.


#139

That was a question coming up :smile: there is obviously a small lag where the call is happening, obviously having a call per data field would be problematic.

How would you parse ‘post’ response and pick the data into the entity fields to be updated?

api.EntityType(name).Fields(name).Exists();

would become something like;

api.EntityType(Room).Fields(Guest Status).Exists(responseObject.booking_status;);
api.EntityType(Room).Fields(Guest Name).Exists(responseObject.guests[0].firstname return responseObject.guests[0].lastname);

How do you work in multiple parse values?


#140

Comma separated should work.


#141

Notice there is no parameter in Exists(). The Method will return True or False. You may want to use that method before performing an update, but the update itself will occur in this method instead:

api.Entity(name).Data(name).Update(value);


if (api.EntityType(Room).Fields(Guest Status).Exists() == True) {
  api.Entity(RoomName).Data(Guest Status).Update(responseObject.booking_status);
}

#142

If doing multiple updates?
Like this?

 var response = web.PostJson(url,jsondata,username,password);
 var responseObject = JSON.parse(response);
 api.EntityType(Room).Fields(Guest Status).Update(responseObject.booking_status;);
 api.EntityType(Room).Fields(Guest Name).Update(responseObject.guests[0].firstname responseObject.guests[0].lastname);
}

Obviously only the end of the script.

Also could a field be updated with two values?;

Update(responseObject.guests[0].firstname responseObject.guests[0].lastname)

Would i need to att something like +’ '+

Update(responseObject.guests[0].firstname+' '+responseObject.guests[0].lastname)

#143

Just notices the bookings_inhouse_list url which is probably the best one to go from but will result in some eppic code LOL
It returns an arrayed list of all the booking values in sub arrays for each site (room)
See aprox 20 keys/lines of booking details and hotel has 32 rooms :slight_smile: will be some interesting code, not sure if excited at trying or dreading it LOL