So am I understanding right with the new web.PostData in theory my code will look something like;
function JSONTest()
{
var url = 'https://sambapos:xxxxxxxxxxxxxxxxxxxxxxx@testau.newbookpms.com/rest/auth_test';
var api = '{\"api_key\":\"instances_xxxxxxxxxxxxxxxxxx\"}';
var response = web.PostData(url,api);
var responseObject = JSON.parse(response);
return responseObject.json.success;
}
if the expected post result options were;
{"success":"You have successfully authenticated to NewBook Test Property"}
Which with any luck would give result of
You have successfully authenticated to NewBook Test Property
There are three error outputs I have seen so far which are;
{"error":"Authentication Required"}
{"error":"API Key not provided"}
{"error":"Could not decode JSON data\n<!-- XXXXXXXXXXXXXXXXXX -->"}
so if not expected result or no result changine success to error should show the error message reason?
I wasnt expecting it to work but thought I would try⊠if I use the web.Upload as below;
function JSONTest()
{
var url = 'https://sambapos:xxxxxxxxxxxxxxxxx@testau.newbookpms.com/rest/auth_test';
var api = '{\"api_key\":\"instances_xxxxxxxxxxxxxxx\"}';
var response = web.Upload(url,api);
var responseObject = JSON.parse(response);
return responseObject.json.success;
}
Test gives message of âjson.successâ is null or not an object, hopefully this is because Upload doesnât look for response vs PostData as sugested by QMcKay
I know what your saying but the documentation and from my understanding is you âPOSTâ the
{"api_key":"instances_xxxxxxxxxxxxxxxxxxxxxx"}
to the REST address based on the request,
The responce is JSON values.
The auth_test url will return one of the above,
If it works and returns
{âsuccessâ:âYou have successfully authenticated to NewBook Test Propertyâ}
the value for success would be You have successfully authenticated to NewBook Test Property
Either that or I have misunderstood the whole thing.
function JSONTest()
{
var url = 'https://sambapos:xxxxxxxxxxxxxxxxxxxxxx@testau.newbookpms.com/rest/auth_test';
var api = '{"api_key": "xxxxxxxxxxxxxxxxxxxxxxxxxx"}';
var response = web.Upload(url,api);
var responseObject = JSON.parse(response);
return responseObject.json.success;
}
yes, {âapi_keyâ:âinstances_xxxxxxxxxxxxxxxxxxxxxxxxxxxâ} in custom data in RESTezey firefox plugin works.
However it has specific firelds for HTTP Basic Auth but beleive it should work with the user:password@ prefix on url
It is probably the web.Upload not working like we think it might be.
in theory this should work.
function JSONTest()
{
var url = 'https://sambapos:xxxxxxxxxxxxxxxxxxxxxx@testau.newbookpms.com/rest/auth_test';
var api = '{\"api_key\":\"instances_xxxxxxxxxxxxxxx\"}';
var response = web.PostData(url,api);
var responseObject = JSON.parse(response);
return responseObject.json.success;
}
That is assuming the \ were escape for "
When .48 comes out we can test that. Unless @emre wants to be nice and test it for us lol.
{âerrorâ:âAuthentication Requiredâ} is issue with the user and password rather than API
If API not received it would give {âerrorâ:âAPI Key not providedâ}
having sambapos:xxxxxxxxxxxxxxxx@ in the url obviously isnt working for the auth
So they have not enabled HTTP Basic authentication they are only using Basic Authentication. We may need a helper from Emre for this to work but i will research more.