SambaPOS API Integration with NewBook PMS/Booking System


Ok, to avoid confusion, this does not exist in the API …

api.EntityType(Room).Fields(Guest Status).Update(value);

This is correct …

api.Entity(Room).Fields(Guest Status).Update(value);

Yes, that would work, and yes you need to join them as such, because firstname and lastname will contain string content.


I was only going from emres post;


I was about to ask if you could get everything in one call, for all rooms,dates, etc. That would be the way to go.

Parsing it may not be as difficult as you think. You run it through a loop to match room names and update data for each Entity.

If you can capture the JSON, paste it here in a code block and it will be easier to decipher.


I cant C&P from the test popup.

This is the script;

function bookinhouse()
 var url = '';
 var api = '{\"api_key\":\"instances_xxxxxxxxxx\"}';
 var username = 'sambapos';
 var password = 'xxxxxxxxxx';
 var response = web.PostJson(url,api,username,password);
 var responseObject = JSON.parse(response);
 return response;


Right. Read it again. The example you show uses a method that does not exist…

api.Entity***Type***(Room).Fields(Guest Status).Update(value);

while this does exists …

api.Entity(Room).Fields(Guest Status).Update(value);


I changed it didn’t I :slight_smile: was the exists one until you pointed out it should have been update


Did you see this one?;

There is ALLOT OF INFO hehe


Yah, bit of a bugger there eh?

You’ll need to use HTML page to dump the output to copy/paste.

… or return the value and use the SambaPOS Helper object file.WriteToFile(filename, content) to get it in a text file.


Like that?

Obviously not, just tried LOL


LOL, yah, I corrected the syntax in my post above. It is actually:

file.WriteToFile(filename, content);

So, do this:

file.WriteToFile('C:\jsondata.txt', response);

function bookinhouse()
 var url = '';
 var api = '{\"api_key\":\"instances_xxxxxxxxxxxxxxx\"}';
 var username = 'sambapos';
 var password = 'xxxxxxxxxxx';
 var response = web.PostJson(url,api,username,password);
 var responseObject = JSON.parse(response);
 file.WriteToFile('C:\jsondata.txt', responseObject);

Gives this message;


Basically the error issaying one or more of the string parameters in WriteToFile(string, string) it expects are not valid. Likely because responseObject is not a string, but it is an Object. So…

Try this:

file.WriteToFile('C:\jsondata.txt', response);


Thats gives message [undefined]
Double checked putting return response back in and rest is OK


Escape the backslash or spin it around… one (actually 2) of these should work…

file.WriteToFile('C:\\jsondata.txt', response);  // I vote for this one
file.WriteToFile('C:/jsondata.txt', response);   // my second choice
file.WriteToFile('C:\\jsondata.txt', responseObject);
file.WriteToFile('C:/jsondata.txt', responseObject);


double back slash worked! :smile:
[file removed] (6.9 KB)
Any ideas how to reformat that it to something more legible?


Just had a call, neep to nip out, will be late by time I get back so will have to pick this up again tomorrow.
Thanks again for the help again :smile:


Used some find/replace to insert some linefeeds for easier readability…

[file removed] (7.4 KB)


Thanks :smile:

Will probably need some guidance on looping the field updates between fields and then entities but plenty to work with for now.
Cheers again :slight_smile:


This is the correct way to build JSON format.

  var contact = new Object();
  contact.firstname = "Emre";
  contact.surname = "Eren"; = ["555-0100", "555-0120"];
  return JSON.stringify(contact);


Also I’ll teach you one of the best Windows OS tips I’ve ever learned in my life.

You can press Ctrl+C on any windows popup dialog to copy contents to clipboard. :wink: