Reading a Global Setting in a script

Latest update on this is pretty depressing.

I took a new machine and did the following

Note machine is NOT on my network but is obviously connected to internet though a seperate connection.

Updated the Windows 10 version so it was fully up to date
Installed .Net Frameworl 4.6.2
Installed Windows Server 2017 Fresh Install configured Database as SAMBAPOS5
Installed SambaPOS Pro (5.2.3) and set Database Path to Server installation on the same machine.
Restored my test database into SambaPOS.
Set DWORD SchUseStrongCrypto value to 1 on all versions of >NET listed in Registry under both locations as detailed before.

SCRIPT STILL DOES NOTHING

Set TLS 1.2 as default protocol in Registry for WinHttp.

STILL NOT WORKING

Disabled SSL and TLS 1.0 and 1.1

STILL NOT WORKING

Have definately run out of ideas and enthusiasm now. I can ping the Beds24 site from here so it should at least be making some connection.

Can I send you my backed up test database? If it loads and runs on your machine it will at least prove the Samba side is working. If you are busy or this is asking too much then no worries.

Since I get Zero response from the post I honestly think that SambaPOS is not executing any web. commands as the script just seems to stop. I can ping the site so the address is right and this identical script works on @JTRTech machine in the UK.

Is there any script that can force TLS 1.2 for the web.PostJson which can be incorporated in the script.

Web helpers work in sambapos I use them constantly. Show your current script.

I am using a test script that Joe has been working on with me. Its a cut down version just to test the post

However it has the passwords to my PMS provider which I will blank out on the Public page

function test(){
	var url = 'https://api.beds24.com/json/getProperty';
	var akey = 'XXXXXXXX';
	var pkey = 'XXXXXXXXXX';
	var username = 'XXXXXXXX';
	var password = 'XXXXXXX';
	var rate = 1.5;
	var requestjson = '{"authentication": {"apiKey": "'+akey+'","propKey": "'+pkey+'"}}';//,"modifyProperty": [{"action": "modify","template4": "'+rate+'"}]}';
	dlg.ShowMessage('json '+requestjson);
	var response = web.PostJson(url,requestjson,username,password);
	return response;
}

This script with my passwords worked great for Joe but does not work on my system or separate PC.

This is a very simple script that should work or at least give me some response or failure message. Just does nothing after the message showing the JSON .

does anyone have a simple script to an open API that I can test from here to prove SambaPOS is executing the post. I can then be sure that the problem is some TLS protocol issue although I have spent 10 days reading up on setting TLS / making TLS default / disabling SSL / nothing makes this script look like it is doing anything.

Got a WordPress website? Pretty sure there is basic API by default in WordPress although you don’t get much info without config it would give a basic API to test with

1 Like

Just as an update to this thread.

I still cannot get my SambaPOS to Post to ANY API and get a response. Something is fundementally broken in the way SambaPOS does a POST because I have copied your working script and I get no response.
I have modified the URL to point at an open API https://jsonplaceholder.typicode.com/todos/1 just to try illicit some response but I get nothing. no error, no connection OK , Nothing.

All the API’s I try to connect to I can access with Postman, Direct script from webpage, or through their own script boxes on the webpages. SambaPOS will not do anything.

I have seen on Net Monitor that I am sending TLS1.2 and have disabled any low encryption Ciphers but cannot connect to my PMS. Am now at a complete halt with no idea where to go next.

Is there any way to set the encryption from the script. I have seen this thread showing the following

.NET 4.6 and above. You don’t need to do any additional work to support TLS 1.2, it’s supported by default.
.NET 4.5. TLS 1.2 is supported, but it’s not a default protocol. You need to opt-in to use it. The following code will make TLS 1.2 default, make sure to execute it before making a connection to secured resource:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
1
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

.NET 4.0. TLS 1.2 is not supported, but if you have .NET 4.5 (or above) installed on the system then you still can opt in for TLS 1.2 even if your application framework doesn’t support it. The only problem is that SecurityProtocolType in .NET 4.0 doesn’t have an entry for TLS1.2, so we’d have to use a numerical representation of this enum value:

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
1
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

How can I incorporate this into my JSon Post

So your still trying to use PostJson with an api that does not support basic auth with user and password in the url?

Here look at this because I think you ignored what @Emre tried to tell you. Basic Auth using jscript helpers

Or you didn’t understand what he meant by webclient class.

1 Like

I did not ignore what Emre said about helpers and in fairness I do not know much about webclient class. I did explore this but could not get a result with this either.

However, the script that works perfectly for @JTRTech and which was tested and proved between us (using my authorisation passwords) does not work for me, either on my main system or the standalone system I have developed to try get this working.

So actually from his machine to the API i wish to connect to, the PostJson works perfectly. When I copy and use EXACTLY the same script it does not work on my main system or the independent server I have set up to test this.

Every other method I use to ping the API or POST to the API functions fine. SambaPOS does not.

I can confirm I could connect to his PMS without issue once I sorted out a different issue.
It worked for me and only related change on mine is the tls1.2 from my PMS scripts.

So it probably is not a sambapos issue then. We need to figure out what on your system is preventing it.

I’m stumped, think main system uses a server Windows on server so suggested trying Windows 7 or 10 as that’s what I have between machines which I think is what he refers to as the separate machine.
I think something may have changed in samba as I can replicate absolutely no response by setting incorrect password so thing there has been a change in the JSON post helper which effects responses as sure I have had unautherised/wrong cradentials before now. Which if it is the case makes it hard to debug if can’t get error response. Seem to now only get anything back if something is returned from API, no helper error message.

So after much manipulation and frustration I can finally post from the POS to my PMS API. I still get no error messages or confirmations from SambaPOS but have seen the updates working. I know a lot more about protocols and Ciphers than I ever thought possible. selecting and ordering Ciphers seems to have opened the door.

Many thanks to all who assisted and in particular to @JTRTech who gave up a considerable amount of personal time to help.

So its onto the automation and scripting now to get the integration working. Traffic POS to PMS is cracked. Now to read up on the Samba API for traffic in the other direction.

Good to hear you got it working at last.

Can’t comment on connection error messages but post errors would typically be sent as response by the receiving API.
Newbook returns a response to pretty much everything, every post which they receive returns a success or error array with some data then the actual data you want/need but yours may not, you would need to check documentation.

The other way round would have to be done by your PMS.
What are you planning to have coming back from PMS?
My NewBook intergration is all one ended, samba fetches room and booking info and also send the sales data etc.
Your unlikely to get the PMS to push data untill samba can have the demand of say irc touch of use with that PMS.

I made mine sync all sales data.
Room posts of charges to room bills are done there and then, cash over counter sales are routinely synced using ticket states to track what’s been passed and what hasn’t.
Booking data is also routinely fetched.
The routine syncs are triggered by a trigger/Cron job. But note that triggers do not fire while a ticket is open. For that reason I leave the headless server terminal with samba running on login screen and set the trigger rule mapping to the server to ensure it triggers as expected and only once on server.
If you do this be sure to login to server a couple of times a week to make sure samba is still running. I think some busy nights the script gets long and times out crashing samba on the server.
Additionally as a backup I made two newbook buttons on nav screen which allow a manual push of sales data and a manual fetch of booking data.
I also set a separate trigger for 11:59 to push sales data through before midnight as PMS uses midnight cutoff reporting.
Also another script call to push any outstanding tickets through when work period is closed.

1 Like

The issue now that I am experiencing is that I cannot get data from the API because SambaPOS always returns a null value even on a valid post.

This is not a problem when posting new data to the Beds24 API because the data is being posted and is updated on Beds24.

However when I try to get data on a specific booking SambaPOS returns “undefined” as message where the same JSON string posted outside SambaPOS returns all the relevant information for the booking.

This is the script which is slightly modified from my fully working script which posts data to the API. It posts to a different URL relating to settting information and the JSON string is different as it only reads info. as stated above the JSon string works perfectly when posted outside of SambaPOS.

I am aware my script could be more elegant but if it works it works!

function getbalance() {

//“SELECT [Value] FROM [ProgramSettingValues] WHERE [Name]=’”+‘AS Entity Balance’+"’"
var response = “”;
var qry = “”;
var res = “”;
var qry1 = “”;
var res1 = “”;
var bkid = “UNKNOWN”;
var acbal =“UNKNOWN”;

qry = ‘{setting:getGlobalSetting(name:“AS Account Number”){name,value}}’;
res = gql.Exec(qry);
res = JSON.parse(res);
bkid = res.data.setting.value;
//return bkid;

qry1 = ‘{setting:getGlobalSetting(name:“AS Entity Balance”){name,value}}’;
res1 = gql.Exec(qry1);
res1 = JSON.parse(res1);
acbal = res1.data.setting.value;
//return acbal;

var url = ‘https://www.beds24.com/api/json/getBooking’;
“XXXXXXXXXX”,“propKey”: “XXXXXXXXXXX”}’;
var jsondata = ‘{“authentication”: {“apiKey”: “XXXXXXXX”,“propKey”: “XXXXXXXX”},“bookId”: “8218223”,“includeInvoice”: false,“includeInfoItems”: false}’;
dlg.ShowMessage(‘Json’+jsondata);
var response = web.PostData(url,jsondata);
return response;
}

Let me have a play using that script we tested before.
A get request should return the data.
You would need to parse to specify bits but raw should be a string.
Can you post the script we tested before?
That returned data…

Hold off a while, I seem to have found my error. The format of my JSon string seems to have too many curlies.

Dont expend any unnecessary time I will post in a while and let you know how dumb I am.

Yes its official. I am being dumb. Too many curly brackets.

I can succesfully write and read the API so I will refrain from any future premature posting syndrome. Unless I really get stuck.:wink:

1 Like

If you want some screenshots of my setup for rutine fetch automation just shout.

Thanks i appreciate the offer. I will let you know.

Actually now the posts are working I can enjoy myself writing the automation.