Message

API for accessing accessing messages

Listing Messages

The route for listing messages is:

GET /messages
API Call: Listing messages
URL/messageshttp://g8teway.com/api/v2/messages
HTTP MethodGET
Request ParametersretOptional
Default: id, time
Allowed: id, unitid, userid, fromto, time, channelid, content, replyto, timeout, status
statusOptional. Message status
Default: Any
Allowed: 0 (new), 1 (sent), 2 (received), 3 (failed)
timedoutOptional. Include timed-out messages
Default: False
unitidsOptional. List of unitids
Default: Any units
fromOptional. Minimum date
Default: No minimum
toOptional. Maximum date
Default: No maximum
useridsOptional. List of user ids
Default: Any user
directionOptional. Message direction
Default: Any direction
Allowed: unittouser or usertounit
messageidsOptional. List of message ids
Default: Any id
replytoOptional. : List of reference message ids
Default: Any reference
channelidsOptional. List of channels
Default: Any channel

|_. Attribute |_. Meaning | | ret | Fields to retrieve when getting data from the Web Service
Default: id, time Allowed: id, unitid, userid, fromto, time, channelid, content, replyto, timeout, status |

You would get a list of messages like this:

$ curl 'http://g8teway.com/api/v2/messages.json?ret=unitid,userid,fromto,time,channelid,content,replyto,timeout,status' -b mdi.cookie -c mdi.cookie
[{"message":
   {"status": 0,
    "unitid": 1,
    "fromto": true,
    "timeout": 2880,
    "userid": -1,
    "content": "message2",
    "refid": -1,
    "channelid": 11,
    "datetime": "2009-04-10T10:53:24Z"}},
 {"message":
   {"status": 3,
    "unitid": 3,
    "fromto": true,
    "timeout": 1,
    "userid": -1,
    "content": "message1",
    "refid": -1,
    "channelid": 32,
    "datetime": "2009-04-10T13:03:18Z"}},...]

Sending a new message

The route for creating messages is:

POST /messages
API Call: Listing messages
URL/messageshttp://g8teway.com/api/v2/messages
HTTP MethodPOST
wrapper for all fieldsmessage[ ]Message unit id
Request ParametersunitidMessage unit id
useridOptional. Message user id
Default: current logged in user
timedoutOptional. Include timed-out messages
Default: False
unitidsOptional. You shouldn’t normally use ‘unittouser’,these messages are sent by the device.
Default: usertounit
Allowed: unittouser or usertounit
channelidMessage channel
replytoOptional. Id of previous message
Default: Not replying to a message
timeoutOptional. Message timeout, in minutes
Default: Specified by channeledit’s ‘msgtimeout’
Allowed: Number (max 32767 minutes: approx 22 days; zero means instant message:
not stored, only received if unit/user is currently online), or ‘null’ (infinite timeout)
contentThe content of the message
Allowed: Any amount of binary data
Some channels/devices/protocols have stricter specifications

You would send a message to the untit with id 1 on the channel 11 containing test like this :

$ curl 'http://g8teway.com/api/v2/messages.json' -F "message[unitid]=1" -F "message[channelid]=11" -F "message[content]=test" -b mdi.cookie -c mdi.cookie

And get as response the status code 201 (created) and this json object:

{"message": 
  {"status": 0,
   "unitid": 17,
   "timeout": 2880,
   "id": 3098,
   "fromto": false,
   "userid": 2,
   "refid": -1,
   "content": "test",
   "channelid": 11,
   "datetime": "2009-05-28T11:55:35Z"}}