MyChat REST API allows connecting to the MyChat Server via GET or POST queries.

 

Query structure


  1. Host address or server IP
  2. Entrance path /API/?data=
  3. JSON object that stores fields and their values

 

How does it work?


For example, let's send a GET quesry on  IP 192.168.10.100. MyChat WEB server works on default 80 TCP port (https, 443 port can be used after additional configuration):


http://192.168.10.100/API/?data={"cmd":"0011","UserName":"Glubber","Message":"Hello","LinkToPost":"\/viewtopic.php?f=&t=&p=#p","LinkToTopic":"\/viewtopic.php?f=&t=","LinkToProfile":"\/memberlist.php?mode=viewprofile&u=","Subject":"Hello","APIStype":"phpbb","ServerKey":"iddqd"}

 

For correct work the URL is encoded:

http://192.168.10.100/API/?data=%7B%22cmd%22%3A%220011%22%2C%22UserName%22%3Anull%2C%22Message%22%3Anull%2C%22LinkToPost%22%3A%22%5C%2Fviewtopic.php%3Ff%3D%26t%3D%26p%3D%23p%22%2C%22LinkToTopic%22%3A%22%5C%2Fviewtopic.php%3Ff%3D%26t%3D%22%2C%22LinkToProfile%22%3A%22%5C%2Fmemberlist.php%3Fmode%3Dviewprofile%26u%3D%22%2C%22Subject%22%3Anull%2C%22APIStype%22%3A%22phpbb%22%2C%22ServerKey%22%3A%22iddqd%22%7D

 

Example of message sending to the chat on php language


A private message is sent on behalf of the built-in bot (UIN 0) for a user with UIN = 1. Nicknames or emails can be used instead of UIN.


$host = '192.168.10.100';
$portWEB = '80';
$typeOfConnection = 'http';
$integrationAPIKey = 'iddqd';
$cmd = '0002';
$userTo = '1';
$userFrom = '0';
$msg = 'hello';
$toolName = 'php';
$json = json_encode(array('cmd'=>$cmd, 'UserTo' =>$userTo, 'UserFrom' =>$userFrom, 'Msg'=>$msg, 'APIStype'=>$toolName, 'ServerKey'=>$integrationAPIKey));
$json = urlencode($json);
$URL = $typeOfConnection.'://'.$host.':'.$portWEB.'/API/?data=' . $json;
file_get_contents($URL);


If your server uses encryption, we insist on using cURL with configuration to ignore encryption when sending a query with the help of curl_setopt().

 

See also

1C 8.xx

C#

Delphi XE3

Python

Working via sockets