Phone Janitor Web API Reference
Version 1.0, updated July 20th 2015
All the functionality of Phone Janitor is exposed through a set of web-accessible interfaces.
These interfaces make it possible to automate account management and build new features on top of the system.
Every API call takes the form of an HTTP POST request directed at a URL which indicates the API function you wish to call. URLs always begin with https://phonejanitor.com/api/, followed by the function name. The content of the POST is a JSON Object which provides arguments for the API call, such as account credentials.
The response will similarly be a JSON string which either contains the requested data, an indication that the call succeeded or an error message indicating that the call failed. If the call succeeded, results will be stored in a JSON object with the key value, while error messages will be stored with the key error.
Most API calls are authenticated using a session token. Calling beginSession with an account username and password will produce such a token. Existing session tokens are automatically invalidated if beginSession is called, or can be explicitly invalidated with endSession. Calling checkSession allows user code to test whether a token is still valid. Session tokens will automatically expire after 1 hour of inactivity, not counting checkSession.
Imagine a user with an account named "Steve" had a password "un$4n1tAry" and owned the endpoint (phone number) "1-(555)-867-5309". Steve wants to write a script that allows him to see if he has any new voicemail messages. First, Steve needs to call beginSession to get an API token, and then he can make other calls. The API call getVoicemail will provide the information he needs, so he writes a quick Python program:
#!/usr/bin/env python
import json
import urllib2
# obtain a session token
credentials = {"username": "Steve", "password": "un$4n1tAry"}
authrequest = urllib2.Request("https://phonejanitor.com/api/beginSession", json.dumps(credentials))
authtoken = json.loads(urllib2.urlopen(authrequest).read())["value"]
# request the contents of the voicemail inbox
payload = {"token": authtoken, "number":"15558675309"}
request = urllib2.Request("https://phonejanitor.com/api/getVoicemail", json.dumps(payload))
newmail = json.loads(urllib2.urlopen(request).read())["value"]["new"]
if any(newmail):
print "You have a new voicemail!"
else:
print "No unheard voicemail today."
# manually expire the session token
# (not strictly necessary, but a good practice)
logoff = urllib2.Request("https://phonejanitor.com/api/endSession", json.dumps({"token": authtoken}))
urllib2.urlopen(logoff)
The full JSON response from this call may have looked something like:
{
"value": {
"caller": ["Richard Fawkes", "Janet H."],
"number": ["1-557-8001", "1-555-1551"],
"time" : ["2015-05-24 03:45:01.0", "2015-05-23 09:10:30.0"],
"new" : [false, true],
"audio" : ["820df6f4-1902-11e5-b60b-1697f925ec7b", "820df6f4-1902-11e5-b60b-1697f925ec7b"],
"id" : [1401, 1711]
}
}
Note that the data is returned in a columnar fashion rather than as a list of tagged records. All API functions which return bulk data use a similar approach. All the columns returned will always be the same length.
If Steve had provided an incorrect username or password, he might have instead received:
{
"error": "invalid credentials."
}
The following API calls are supported. See each subsection for details:
| Function Name |
Since Version |
Description |
| beginSession |
1.0 |
Exchange a user name and password for a temporary session token. |
| endSession |
1.0 |
Exchange a user name and password for a temporary session token. |
| checkSession |
1.0 |
Determine whether a session token is still valid. |
| createAccount |
1.0 |
Register a new user account and begin a session. |
| checkUsername |
1.0 |
Determine whether a username is already in use. |
| getAccountInfo |
1.0 |
Retrieve assorted preferences associated with an account. |
| setAccountInfo |
1.0 |
Update assorted preferences associated with an account. |
| setPassword |
1.0 |
Update the password associated with an account. |
| getEndpoints |
1.0 |
Retrieve a list of endpoints (phone numbers) associated with an account. |
| getGroups |
1.0 |
Retrieve a list of the names of the groups in an account's contact list. |
| createGroup |
1.0 |
Create a new group in an account's contact list. |
| deleteGroup |
1.0 |
Remove a group from an account's contact list. |
| setInGroup |
1.0 |
Add a contact to or remove a contact from a group. |
| getContacts |
1.0 |
Retrieve an account's contact list, including membership in groups. |
| createContact |
1.0 |
Create a new entry in an account's contact list. |
| deleteContact |
1.0 |
Remove an entry from an account's contact list. |
| setContactName |
1.0 |
Update the name of an existing contact. |
| getCalls |
1.0 |
Retrieve the call log for an endpoint, including caller ID, time and duration. |
| getVoicemail |
1.0 |
Retrieve the voicemail log for an endpoint. |
| setVoicemailRead |
1.0 |
Indicate that a voicemail has been read. |
| deleteVoicemail |
1.0 |
Remove a voicemail record, including its recording. |
| getRuleSet |
1.0 |
Retrieve a list of routing scripts for an endpoint. |
| setActiveRules |
1.0 |
Select the routing script which should currently be used for an endpoint. |
| getRules |
1.0 |
Retrieve a particular routing script for an endpoint. |
| setRules |
1.0 |
Update or create a routing script for an endpoint. |
API Function Details
Exchange a user name and password for a temporary session token. Returns token as a UUID string. Accounts may be locked for billing or maintenance purposes. If the current account is locked, the response will contain a key detail with a human readable description of the reason for the account lock and no session token will be returned.
| Argument |
Type |
Description |
| username |
String |
Account username. |
| password |
String |
Account password. |
Invalidate an existing session token. Returns "ok" if successful.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
Determine whether a session token is still valid. Polling periodically with this call can be used to determine when a token has been invalidated via a timeout or the creation of a new session for this user. Returns a boolean, true if the token is still valid.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
Register a new user account and begin a session. Note that at the API call level no validation of password length or other properties is performed. Exercise caution and use short or easily-guessed passwords at your own risk. Returns a session token as a UUID string.
| Argument |
Type |
Description |
| username |
String |
Account username. |
| password |
String |
Account password. |
| email |
String |
Account contact email address. |
Determine whether a username is already in use. Returns a boolean, true if the given username is already in use.
| Argument |
Type |
Description |
| username |
String |
Account username. |
Retrieve assorted preferences associated with an account. Returns a JSON object containing several keys:
| Key |
Type |
Description |
| email |
String |
The contact email address associated with this account. |
| pin |
String |
A 6-digit PIN for accessing the voicemail system. |
| timezone |
String |
A TZDB time zone name. |
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
Update assorted preferences associated with an account. Returns "ok" if successful.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| email |
String |
A new email address. (Optional) |
| pin |
String |
A new 6-digit voicemail PIN. (Optional) |
| timezone |
String |
A TZDB time zone name. (Optional) |
Update the password associated with an account. Note that at the API call level no validation of password length or other properties is performed. Exercise caution and use short or easily-guessed passwords at your own risk. Returns "ok" if successful.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| replacement |
String |
The new password. |
Retrieve a list of endpoints (phone numbers) associated with an account. Returns a JSON object with columnar data for each endpoint:
| Key |
Type |
Description |
| number |
Array of String |
The phone number for each endpoint. |
| rules |
Array of String |
The title of the active rule set for each endpoint. (See setActiveRules, getRuleSet.) |
| lastbill |
Array of String |
Date stamps for the last time this endpoint's monthly bill was paid. |
| nextbill |
Array of String |
Date stamps for the next time this endpoint's monthly bill will be due. |
Note that lastbill and nextbill are best-effort data for informational purposes only and not binding. Both fields may contain the string "never", for example if any of the endpoints are a temporary line.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
Retrieve a list of the names of the groups in an account's contact list. Returns a JSON array of strings.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
Create a new group in an account's contact list. Returns "ok" if successful.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| name |
String |
The name of the new group. Must be unique per account. |
Remove a group from an account's contact list. Returns "ok" if successful.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| name |
String |
The name of the group to remove. Must be unique per account. |
Add a contact to or remove a contact from a group. Returns "ok" if successful.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| id |
Number |
The id of a contact. See getContacts. |
| name |
String |
The name of a group. |
| value |
Boolean |
If true, add the contact to group. If false, remove the contact from the group. |
Retrieve an account's contact list, including membership in groups. Returns a JSON object containing several JSON arrays with columnar data:
| Key |
Type |
Description |
| name |
Array of String |
The names of each contact. |
| number |
Array of String |
The phone number associated with each contact. |
| id |
Array of Number |
The unique id associated with each contact. |
More than one contact entry can have the same name.
Contacts are logically defined by the number they're associated with, and all API calls use the unique contact id when referring to a contact.
The result of calling getContacts will additionally contain several arrays of booleans keyed to each group (see getGroups) in an account's contact list. Each of these arrays will have the name of a group with the prefix group- as a key. The array contains true for each contact in the given group.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
Create a new entry in an account's contact list. Returns a JSON object with the key id and a value indicating the unique contact id of the new contact.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| name |
String |
The name of the new contact. |
| number |
String |
The phone number of the new contact. |
Remove an entry from an account's contact list. Returns "ok" if successful.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| id |
Number |
The id of a contact. See getContacts. |
Update the name of an existing contact. Returns "ok" if successful.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| id |
Number |
The id of a contact. See getContacts. |
| replacement |
String |
The new contact name. |
Retrieve the call log for an endpoint. Returns a JSON object containing several JSON arrays with columnar data:
| Key |
Type |
Description |
| caller |
String |
The name (via caller ID or your contact list) of the caller. |
| number |
String |
The phone number of the caller. |
| time |
String |
A yyyy-mm-dd hh:mm:ss timestamp of when the call occurred. |
| duration |
String |
An hh:mm:ss timespan indicating the length of the call. |
| memo |
String |
A human-readable description of how the call was handled/routed. |
The memo field has no defined format and is purely for descriptive purposes. The caller field will contain the name associated with the phone number at the time of the call- consumers of this API may choose to instead display the most current information from the contact list where applicable.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| number |
String |
An endpoint (phone number). See getEndpoints. |
Retrieve the voicemail log for an endpoint. Returns a JSON object containing several JSON arrays with columnar data:
| Key |
Type |
Description |
| caller |
String |
The name (via caller ID or your contact list) of the caller. |
| number |
String |
The phone number of the caller. |
| time |
String |
A yyyy-mm-dd hh:mm:ss timestamp of when the call occurred. |
| new |
Boolean |
Has this message been marked as viewed? See setVoicemailRead. |
| audio |
String |
A GUID permitting the retrieval of the voicemail recording. |
| id |
Number |
The unique id associated with each voicemail message. |
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| number |
String |
An endpoint (phone number). See getEndpoints. |
Indicate that a voicemail has been read. Returns "ok" if successful.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| number |
String |
An endpoint (phone number). See getEndpoints. |
| id |
Number |
A voicemail message id. See getVoicemail. |
Remove a voicemail record, including its recording. Returns "ok" if successful.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| number |
String |
An endpoint (phone number). See getEndpoints. |
| username |
String |
Account username. |
| password |
String |
Account password. |
| id |
Number |
A voicemail message id. See getVoicemail. |
Retrieve a list of the titles of routing scripts for an endpoint. Every endpoint has one or more possible routing scripts associated with it. When a new endpoint is created, it will be given a routing script called "default rules". This routing script will be used unless another script is selected via a call to setActiveRules. A call to getEndpoints can be used to determine the title of the current active routing script for each endpoint. Returns a JSON Array of strings representing the title of each available routing script.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| number |
String |
An endpoint (phone number). See getEndpoints. |
Select the routing script which should currently be used for an endpoint. The routing script title should be one of the possibilities listed by getRuleSet, or this operation will fail, leaving the endpoint's routing script unchanged. Returns "ok" if successful.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| number |
String |
An endpoint (phone number). See getEndpoints. |
| title |
String |
A routing script title. See getRuleSet. |
Retrieve a particular routing script for an endpoint, based on a title. The routing script title should be one of the possibilities listed by getRuleSet. Returns a JSON array containing routing rules.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| number |
String |
An endpoint (phone number). See getEndpoints. |
| title |
String |
A routing script title. See getRuleSet. |
Update or create a routing script for an endpoint. If the routing script title provided already exists (see getRuleSet), it will be replaced- otherwise a new script will be created. The format of the routing script will be validated before insertion and error messages will attempt to describe any manner in which it is malformed. Returns "ok" if successful.
| Argument |
Type |
Description |
| token |
String |
A session token. See beginSession. |
| number |
String |
An endpoint (phone number). See getEndpoints. |
| title |
String |
A routing script title. See getRuleSet. |
| rules |
Array |
A routing script. See Rules. |
Rules form the basis of PhoneJanitor's core functionality: routing calls. A set of rules, or a "routing script" is represented as a JSON array containing a series of entries. Each entry has a list of conditions (such as who is calling or the time of day) and a list of actions (such as forwarding the call or sending it to voicemail) which should be performed if all the conditions are true. Both actions and conditions have a type field which indicates what, if any, additional parameters it should have. The structure of a set of Rules may be validated via setRules.
The following routing script contains two entries: if a family member calls during work hours, the call should be routed to the user's office phone, and if Jenny the Telemarketer tries to call it should go straight to voicemail.
[
{
"conditions": [
{
"type": "callerInGroup",
"group": "Family"
},
{
"type": "timeOfDay",
"span": "after",
"time": "09:00:00"
},
{
"type": "timeOfDay",
"span": "before",
"time": "17:00:00"
}
],
"actions": [
{
"type": "callContact",
"id": 10
}
]
},
{
"conditions": [
{
"type": "callerIsContact",
"id": 32
}
],
"actions": [
{
"type": "sendToVoicemail"
}
]
}
]
Every endpoint has one or more associated routing scripts, exactly one of which is "active" at any given time. This makes it possible to set up a number of configurations and switch between them easily. See getRuleSet and setActiveRules for more information.
Condition Types
| Type |
Since Version |
Description |
| callerInGroup |
1.0 |
The caller belongs to a contact group. |
| callerIsContact |
1.0 |
The caller is a specific contact. |
| callerHasNumber |
1.0 |
The caller has a specific phone number. |
| currentDate |
1.0 |
The call occurs before or after a specific date. |
| dayOfWeek |
1.0 |
The call occurs on a specific day, or any weekend/weekday. |
| timeOfDay |
1.0 |
The call occurs before or after a particular hour of the day. |
| anyCall |
1.0 |
A wildcard that matches any call. |
The caller belongs to a contact group. Requires a group argument specifying a group name.
The caller is a specific contact. Requires a id argument specifying a contact id. (See getContacts.)
The caller has a specific phone number. Requires a number argument specifying a phone number.
The call occurs before or after a specific date. Requires a date argument specifying a date in yyyy-mm-dd format. Requires a span argument which must be one of the strings "before", "on" or "after".
The call occurs on a specific day of the week. Requires a day argument which must be one of the strings "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" or one of the wildcards "anyWeekday" or "anyWeekend".
The call occurs before or after a particular time of day. Requires a time argument specifying a time of day in hh:mm:ss format, which is assumed to be in GMT. Requires a span argument which must be one of the strings "before", or "after".
A wildcard that matches any call. Takes no arguments.
Action Types
Currently all action types are exclusive, and thus it is only valid for the action list to contain a single action. In the future, support for additional action types will be added which may be combined with these "terminal" actions:
| Type |
Since Version |
Description |
| callContact |
1.0 |
Forward the call to a specific contact. |
| callNumber |
1.0 |
Forward the call to a specific phone number. |
| sendToVoicemail |
1.0 |
Forward the call to this endpoint's voicemail box. |
| dropCall |
1.0 |
Drop the call completely. |
Forward the call to a contact. Requires a id argument specifying a contact id. (See getContacts.)
Forward the call to a phone number. Requires a number argument specifying phone number to dial.
Forward the call to this endpoint's voicemail box. Takes no arguments.
Drop the call completely, hanging up on the caller. Takes no arguments.
© 2015, The Network Sanitation Comittee