OK, first question on the script;
To pull a particular rooms/booking info I need to add a second JSON line of data.
Documentation says:
{
“api_key”: “your_api_key_here”,
“site_name”: “xxxxxx”
}
Now I presume that the values in the web.PostJson(url,api,username,password)
are in a specific order of url,api,username,password so api would in reality be data and I will want to build a ‘data’ variable;
This is what I have at the minute;
function roombooking(sitename)
{
var url = 'https://testau.newbookpms.com/rest/site_inhouse_booking';
var username = 'sambapos';
var password = 'xxxxxxxxxxxxx';
// var api = \"api_key\":\"instances_xxxxxxxxxxxxx\";
var jsondata = '{\"api_key\":\"instances_xxxxxxxxxxx\",\"site_name\":\"xxxxxx\"}';
var response = web.PostJson(url,jsondata,username,password);
var responseObject = JSON.parse(response);
return response;
}
And testing with roombooking()
gives expected result of the booking data inn JSON format.
HOWEVER obviously from the function roombooking(sitename)
my intention is to feed the sitename in to the jsondata but
var jsondata = '{\"api_key\":\"instances_xxxxxxxxxxx\",\"site_name\":\"sitename\"}';
Doesnt work, presumably because of the ’ ’ quotes arround the JSON { } - without them you get invalid character.
Any advice?
How can I set a variable within the JSON data?
Thought id try splitting the ’ ’ quoted sections;
var jsondata = '{\"api_key\":\"instances_xxxxxxxxxxxxx\",\"site_name\":\" ' sitename ' \"}';
(have added a little spacing for viewing - actual code has no extra spacing around the quotes.
with test of
roombooking('xxxxxxx')
but get expected ‘;’ error