QMcKay
September 10, 2015, 8:37pm
144
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.
JTRTech
September 10, 2015, 8:40pm
145
QMcKay:
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);
I was only going from emres post;
I’ll quickly update this topic to document changes on JS api.
api.PaymentType(name).Processors(name).Exists();
api.PaymentType(name).Processors(name).Create();
api.PaymentType(name).Processors(name).Delete();
api.EntityType(name).Entities().State(name).Update(value);
api.EntityType(name).Fields(name).Exists();
api.EntityType(name).Fields(name).Create(fieldtype,[format],[valuesource],[hidden]);
api.Entity(name).State(name).Update(state);
api.Entity(name).State(name).Get();
api.Entity(name).Data(name).Update(value);
api.Entity(name).Data(name).Get();
api.Entity(name).Exists();
api.Entity(name).Create(entityTypeName);
PS: [param] indicates an optional parameter but you can’t skip parameters. If you want to set third optional parameter you should also set values for former optional parameters.
QMcKay
September 10, 2015, 8:42pm
146
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.
JTRTech
September 10, 2015, 8:44pm
147
I cant C&P from the test popup.
This is the script;
function bookinhouse()
{
var url = 'https://testau.newbookpms.com/rest/bookings_inhouse_list';
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;
}
QMcKay
September 10, 2015, 8:45pm
148
Right. Read it again. The example you show uses a method that does not exist…
api.EntityType (Room).Fields(Guest Status).Update(value);
while this does exists …
api.Entity(Room).Fields(Guest Status).Update(value);
1 Like
JTRTech
September 10, 2015, 8:46pm
149
I changed it didn’t I was the exists one until you pointed out it should have been update
api.EntityType(name).Fields(name).Exists();
1 Like
JTRTech
September 10, 2015, 8:48pm
150
Did you see this one?;
JTRTech:
I cant C&P from the test popup.
This is the script;
function bookinhouse()
{
var url = ‘https://testau.newbookpms.com/rest/bookings_inhouse_list ’;
var api = ‘{"api_key":"instances_xxxxxxxxxxxxxx"}’;
var username = ‘sambapos’;
var password = ‘xxxxxxxxx’;
var response = web.PostJson(url,api,username,password);
var responseObject = JSON.parse(response);
return response;
}
There is ALLOT OF INFO hehe
QMcKay
September 10, 2015, 8:49pm
151
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.
JTRTech
September 10, 2015, 8:50pm
152
QMcKay:
file.Write()
file.Write(c:\jsontest.txt)
Like that?
…
Obviously not, just tried LOL
QMcKay
September 10, 2015, 8:55pm
153
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);
JTRTech
September 10, 2015, 8:58pm
155
function bookinhouse()
{
var url = 'https://testau.newbookpms.com/rest/bookings_inhouse_list';
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;
QMcKay
September 10, 2015, 8:59pm
156
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);
JTRTech
September 10, 2015, 9:01pm
157
Thats gives message [undefined]
Double checked putting return response back in and rest is OK
QMcKay
September 10, 2015, 9:04pm
158
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);
JTRTech
September 10, 2015, 9:08pm
159
double back slash worked!
[file removed] (6.9 KB)
Any ideas how to reformat that it to something more legible?
JTRTech
September 10, 2015, 9:13pm
160
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
QMcKay
September 10, 2015, 9:17pm
161
Used some find/replace to insert some linefeeds for easier readability…
[file removed] (7.4 KB)
JTRTech
September 10, 2015, 9:22pm
162
Thanks
Will probably need some guidance on looping the field updates between fields and then entities but plenty to work with for now.
Cheers again
1 Like
emre
September 10, 2015, 10:03pm
163
This is the correct way to build JSON format.
{
var contact = new Object();
contact.firstname = "Emre";
contact.surname = "Eren";
contact.phone = ["555-0100", "555-0120"];
return JSON.stringify(contact);
}
emre
September 10, 2015, 10:07pm
164
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.
4 Likes