pbx.request() calls and auth object

Community based support for the Digium Phone Application Programming Interface (API).

Moderators: jwitt, sruffell, malcolmd, Moderator

pbx.request() calls and auth object

Postby mollett » Thu May 16, 2013 8:56 am

I've got a D40 running 1.3.0.2 (54153), connected to a Switchvox server running 5.7.1.1 (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.
screen_shot.png
Screen shot of error
screen_shot.png (1.86 KiB) Viewed 12563 times
In looking at what app.getAuth() returns, I must admit that I'm a little confused:

{"lang":
{"parameters":
{"langLocale":"en_us",
"defaultLangLocale":"en_us"
},
"allKeys":
{"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"],
"AUTH_SERVER":["Server"],
"AUTH_EXTENSION":["Extension"],
"AUTH_PASSWORD":["Password"],
"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."],
"GM_BACK":["Back"],
"SI_SELECT_OPTION":["Choose an Option"],
"TC_CHANGE":["Change"],
"TC_NEXT":["Next"],
"TC_PREV":["Prev"],
"STD_SECONDS":["second","seconds"],
"STD_MINUTES":["minute","minutes"],
"STD_HOURS":["hour","hours"],
"STD_OK":["OK"],
"STD_DONE":["Done"],
"STD_YES":["Yes"],
"STD_NO":["No"],
"STD_MORE":["More"],
"STD_REFRESH":["Refresh"],
"STD_SUBMIT":["Submit"],
"STD_SELECT":["Select"],
"STD_CANCEL":["Cancel"],
"STD_HELP":["Help"],
"STD_SUCCESS":["Success"],
"STD_DELETE":["Delete"],
"STD_YESTERDAY":["Yesterday"],
"STD_SUNDAY":["Sunday"],
"STD_MONDAY":["Monday"],
"STD_TUESDAY":["Tuesday"],
"STD_WEDNESDAY":["Wednesday"],
"STD_THURSDAY":["Thursday"],
"STD_FRIDAY":["Friday"],
"STD_SATURDAY":["Saturday"],
"MM_REBOOTING":["Restarting phone, please be patient..."],
"MM_REBOOT":["Restart"],
"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_SELECTED":["Selected"],
"NETSELECT_DONE_MSG":["Successfully saved network."],
"NETSELECT_AUTO_DETECT":["Auto Detect"],
"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');
app.init();

var pbx = require('pbx');

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

pbx.request({
'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");
}
});
Attachments
tiny.zip
app file
(674 Bytes) Downloaded 578 times
mollett
Newsterisk
 
Posts: 25
Joined: Mon Apr 01, 2013 12:03 pm

Re: pbx.request() calls and auth object

Postby sruffell » Thu May 16, 2013 12:46 pm

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?
sruffell
Oldsterisk
 
Posts: 200
Joined: Fri Jan 07, 2011 2:02 pm

Re: pbx.request() calls and auth object

Postby mollett » Thu May 16, 2013 2:27 pm

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!

Vic
mollett
Newsterisk
 
Posts: 25
Joined: Mon Apr 01, 2013 12:03 pm

Re: pbx.request() calls and auth object

Postby mollett » Thu May 16, 2013 2:53 pm

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?
mollett
Newsterisk
 
Posts: 25
Joined: Mon Apr 01, 2013 12:03 pm

Re: pbx.request() calls and auth object

Postby sruffell » Fri May 17, 2013 11:05 am

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!
sruffell
Oldsterisk
 
Posts: 200
Joined: Fri Jan 07, 2011 2:02 pm

Re: pbx.request() calls and auth object

Postby mollett » Sun May 19, 2013 3:30 pm

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.

Thanks!
mollett
Newsterisk
 
Posts: 25
Joined: Mon Apr 01, 2013 12:03 pm

Re: pbx.request() calls and auth object

Postby timo » Mon Jan 06, 2014 12:02 am

Just for those watching this thread as I don't think mollett still needs it ;)

The AuthObject has the following properties / methods:

lang
getCredentials
getAccountId
isLoggedIn
logout
showLoginScreen
login

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

var authObj = app.getAuth();
var Account_ID = authObj.getAccountId();
timo
Newsterisk
 
Posts: 7
Joined: Wed Sep 25, 2013 6:07 am


Return to Digium Phone API

Who is online

Users browsing this forum: No registered users and 1 guest