Pbx.request() calls and auth object

I’ve got a D40 running (54153), connected to a Switchvox server running (54321).

I’ve been experimenting with making pbx.request() calls. Attached is some tiny code that I have been working with, attempting to make the request. When I make the call, I get an error stating “No server defined. Make sure the auth param includes a valid server address.” I originally included the result from app.getAuth() as the parameter, but upon reading “If you want to send the request to the PBX the phone is configured to as the extension the phone is configured as, then this parameter is not needed” in the pbx.request documentation, I took out the auth parameter. Unfortunately, I get the same error regardless of whether I include auth parameter or not. [attachment=0]screen_shot.png[/attachment] In looking at what app.getAuth() returns, I must admit that I’m a little confused:

{“APP_ERROR”:[“Application Error”],
“APP_MISSREQ”:[“Missing required param (%s)”],
“APP_DISABLED”:[“This application is not enabled.”],
“APP_QUESTIONS”:[“If you have any questions,”],
“APP_CONTACT_ADMIN”:[“please contact your PBX administrator.”],
“AUTH_VERIFY_LOGIN”:[“Verifying Login”],
“AUTH_LOGIN_TITLE”:[“Switchvox Voicemail Login”],
“DEMO_STRING”:[“Language Demo String”],
“DEMO_FEET_TALL”:[“I am %s foot tall”,“I am %s feet tall”],
“FAIL_MSG”:[“The phone is in failover mode, this App is temporarily unavailable.”],
“FAIL_TITLE”:["%s App is Unavailable"],
“GC_ARE_YOU_SURE”:[“Are you sure you wish to perform this action?”],
“GC_TITLE”:[“Confirm Action”],
“GM_ERROR”:[“Please fix the following errors:”],
“GF_INVALID_INPUT”:[“Invalid %s”],
“GF_REQUIRED_INPUT”:["%s is a required field."],
“SI_SELECT_OPTION”:[“Choose an Option”],
“MM_REBOOTING”:[“Restarting phone, please be patient…”],
“NETSELECT_TITLE”:[“Select Network”],
“NETSELECT_SAVE_TITLE”:[“Save Settings”],
“NETSELECT_SAVE_MSG”:[“Changing the phone’s network may require a reboot. Press OK to save.”],
“NETSELECT_DONE_MSG”:[“Successfully saved network.”],
“NETSELECT_EMPTY_MSG”:[“No networks found in phone configuration.”],
“PBX_COMM_ERROR”:[“Error communicating with server. Please check the network connection and/or try again.”],
“PBX_BAD_STATUS”:[“Got a bad status back”],
“PBX_XML_ERR”:[“Error parsing XML. (%s)”],
“PBX_JSON_ERR”:[“Error parsing JSON”],
“PBX_MISSING_RESP_TAG”:[“Missing response tag”],
“PBX_RESP_UNDEF”:[“Missing result and errors???”],
“PBX_NO_SERVER”:[“No server defined. Make sure the auth param includes a valid server address.”]

Here’s the code (it’s also attached as a zip file). What am I doing wrong?

var app = require(‘app’);

var pbx = require(‘pbx’);

// print(“app.getAuth()\n” + JSON.stringify(app.getAuth()) + “\n>>>\n”);

‘method’ : ‘switchvox.users.phones.idleScreenImages.getFile’,
‘parameters’ : {
‘image_id’ : ‘1’
‘loadingText’ : ‘Getting info from pbx’,
‘onSuccess’ : function(response) {
print("Got response " + JSON.stringify(response.result) + “\n”);

mollett: The object returned from getAuth, since it’s not a simple data item, cannot be stringified. So that is why the output there is a little confusing.

Normally the server address is defined by default when DPMA / Switchvox passes a config to the phone. Do you get the same error when your server is configured to load and start the app on the phone?

Ah ha! That’s it, I hadn’t loaded the app via Switchvox and set the “Include API Credentials” flag. That makes me wonder, is there a way for the app to tell ahead of time if it has the required data to make a pbx.request() call or not, other than a failed pbx.request() call?

I want to add, that even though I’ve had a lot of questions, I think the app environment on the phone is way cool! Thanks for your all’s hard work!


This is a little bit of a tangent, but perhaps someone can help. I was using pbx.request() to make a switchvox.users.phone.idleScreenImages.getFile call. This call requires an image_id parameter, which I wrongly assumed would be “0” or “1”. It seems that Switchvox is somewhat random in this image_id assignment, and for the 3 phones I checked, the Switchvox-specified image was at id 14, 21, or 22. Clearly the phone is able to get this image, but how is an app to locate the idle screen image that has been specified in Switchvox?

I did a quick grep through the sources and didn’t see any answer to this question, but I’ll have to dig a little more later to see if there is a way for an app to determine this. Again, let me know if this is holding you up in anyway.

BTW: I’m glad that you’re asking all these questions!

Nope, not holding me up. This app is really for my desk phone (it has a “ticker” which gives me basic weather info, and if the NWS issues any warnings for me, it will change the background and tell me what the warnings are). Right now, I’m just packaging a background image file in the zip, but my goal is to allow Switchvox to manage the background image, as it normally does (well, with the exception of the alert image).

I need to experiment a little more, but I have a hunch that the image_id number in Switchvox is a unique number for each deskset. My next step will be to make some general info calls to Switchvox to see if the id is in any of those responses.


Just for those watching this thread as I don’t think mollett still needs it :wink:

The AuthObject has the following properties / methods:


So if you need to access e.g. the account_id just use:

var authObj = app.getAuth();
var Account_ID = authObj.getAccountId();