# Using &kamailio; from Erlang

## RPC calls from Erlang

This module implements the erlang transport and encoding interface for &kamailio; RPCs. It's allowed to call any exported RPC in &kamailio; from erlang node.

The string in RPC response is binary encoded to allow from erlang side conversion into appropriate encoding and further transformations.

Here are some examples:

### Example of RPC call from erlang shell with no response

    (node1@erlang.lan)26> rpc:call('proxy@kamailio.lan',domain,reload,[]).
    ok

### Example, check is line registered

    (node1@erlang.lan)29> rpc:call('proxy@kamailio.lan',ul,lookup,["location","1001@orange.voip"]).
    [{[{<<"Contact">>,
        {[{<<"Address">>,
           <<"sip:1001@10.1.130.138:5161;transport=udp">>},
          {<<"Expires">>,96},
          {<<"Q">>,-1.0},
          {<<"Call-ID">>,<<"5c89766276627815@10.1.130.138">>},
          {<<"CSeq">>,10335},
          {<<"User-Agent">>,<<"Grandstream GXP2000 1.2.5.3">>},
          {<<"Received">>,<<"sip:198.51.100.137:62770">>},
          {<<"Path">>,
           <<"&lt;sip:172.16.23.130;lr;received=sip:198.51.100.137:62"...>>},
          {<<"State">>,<<"CS_SYNC">>},
          {<<"Flags">>,0},
          {<<"CFlags">>,64},
          {<<"Socket">>,<<"udp:172.16.23.130:5070">>},
          {<<"Methods">>,8159},
          {<<"Ruid">>,<<"uloc-5534a79b-37ea-8">>},
          {<<"Instance">>,<<"[not set]">>},
          {<<"Reg-Id">>,0},
          {<<"Last-Keepalive">>,1429543986},
          {<<"Last-Modified">>,1429543906}]}}]}]

### Example get config variable

    (node1@erlang.lan)26> rpc:call('proxy@kamailio.lan',"cfg","get",["registrar","bindip"]).
    [<<"172.16.23.130">>]

### Example get dialog statistics

    (node1@erlang.lan)26>rpc:call('proxy@kamailio.lan',"stats","get_statistics",["dialog:"]).
    [<<"dialog:active_dialogs = 3">>,
     <<"dialog:early_dialogs = 0">>,
     <<"dialog:expired_dialogs = 0">>,
     <<"dialog:failed_dialogs = 2">>,
     <<"dialog:processed_dialogs = 15">>]