Picture of V1p
Registered 1 year 145 days
V1p Thursday, 6 July 2023, 12:12 PM
PBX API don't work for me, and i found another way JavaScript
Did't find anything working in the Sdk website and the Forum, soo i found another way to accessing pbx api from javascript, all needed is go to pbx objects enable devices api and go to Devices Object and enable the app they code:

var devicesApi = start.consumeApi("com.innovaphone.devices"); //Consume Devices API
devicesApi.send({ mt: "GetGateways" }); // send Request
window.addEventListener("message", getMex); //Make Event Listener with Function you prefer
//##Than make the function to take the data required to craft the access link##
function getMex(obj) { //JSON PARSE THE DATA
var objj = JSON.parse(obj.data); //GET EVENT AND FILTER BY TYPE
if (objj.mt == "ApiResult" && objj.msg.mt == "GetGatewaysResult") {
for (gtw in objj.msg.gateways) {
if (objj.msg.gateways[gtw].id == 1) {//FROM THE PBX WITH ID 1 GET HWID AND THE URI
PBXHWID = objj.msg.gateways[gtw].hwId;
PBXURI = objj.msg.gateways[gtw].uri; //SPLIT AND GET PBXID
passthls = PBXURI.split('/');
PBXURI = passthls.at(-2);
PBXCOMP = passthls.at(-6);
LINKSCR = passthls.at(-9);
PBXLINK = "../../" + PBXCOMP + "/devices/passthrough/" + PBXHWID + "/" + PBXURI;
console.log(passthls);
console.log(PBXURI);
}
}
}
}
//##Then we craft a passtrough link for access to PBX Object for example: ##
var url = PBXLINK + "/PBX0/ADMIN/mod_cmd_login.xml?cmd=show&user=*&search=&search-loc=&search-grp=&hide=&xsl=pbx_objs_right.xsl";
//##Then we need to import JQuery in the htm file to make the request to the url##
$.get(url, function (data) {
console.log(data);
var x = data.querySelectorAll("user");
console.log(x);
}
//#In the Attachment the results (sorry for the censorship)#:
Screenshot_2023-06-30_at_10.51.43.jpg

Andreas Fink
Moderator Registered 12 years 277 days
Andreas Fink (innovaphone) Thursday, 20 July 2023, 11:43 AM
Re: PBX API don't work for me, and i found another way JavaScript
Hello Thomas,

the reason the PbxAdminApi does not work on i direct connection from a User to the PBX is a security consideration.

If a specific PBX User has access to an App that has API access to the PbxAdminApi, the PBX User should still be not able to use the PbxAdminApi on the direct connection from User client to the PBX. This way any user with access to an App with activated PbxAdminApi could do any thing on the PBX.

The correct workaround for this is to implement own API in the App, that handles custom requests from PBX User, translates it to a specific PbxAdminApi messages and forwards them to the PBX.

An example of such implementation can be found in the following github repository:
https://github.com/innovaphone/jslicenseexample

The handling of incoming API messages from the client is done here:

The part where the PbxAdminApi is handled is done here:

In this case the response messages are sent directly, but you could implement own handling to filter data or to trigger activities.

The client part, where JSON requests are started is done here:


Best Regards
Andreas Fink
← You can define your color theme preference here