Need some help getting started with JSON-RPC

529 views
Skip to first unread message

Barry O'shaughnessy

unread,
Feb 10, 2020, 1:26:39 AM2/10/20
to CGRateS
Now I'get a basic CGRateS server up and running and talking nicely with FusionPBX I need to learn how to manage CGRateS using something. 

I assume people write their own web consoles to do management and monitoring tasks. So I thought I'd have a crack at using JSON-RPC to do this. Can't seem to find the idiots guide to managing Cgrates thru JSON-RPC though.

Well now I'm stuck and a hoping someone could share an example of how to access the account balance for a tenant such as cgrates.org extention 1001 using JSON-RPC . A couple of other examples would always be welcome.

Either php, python, nodejs or even go would be great but anything that shows how to relate the JSON format to the GO API.


Barry O'shaughnessy

unread,
Feb 10, 2020, 3:14:27 AM2/10/20
to CGRateS
OK I've got a general idea. telneting in to localhost 2012 and trying


{
"id":"0",
"jsonrpc":"2.0",
"method":"ApierV2.AttrGetAccount",
"params":[
{
"tenant":"cgrates.org",
"Account":"1001"
}]
}


but getting


{"id":"0","result":null,"error":"rpc: can't find service ApierV2.AttrGetAccount"}



cgrates.json have


"listen": {
"rpc_json": ":2012",
"rpc_gob": ":2013",
"http": ":2080",
},


and


"apiers": {
"enabled": true,
"scheduler_conns": ["*internal"],
},

A couple of questions: What am I missing to resolve "rpc: can't find service ApierV2.AttrGetAccount" and is there an API call that will list the services available?

Paul Walsh

unread,
Feb 10, 2020, 3:35:28 AM2/10/20
to cgr...@googlegroups.com
Hi Barry

Have you seen the godoc for the API?

Cheers
Paul

--
You received this message because you are subscribed to the Google Groups "CGRateS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cgrates+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cgrates/06dbd2fa-d8ce-4394-8d47-8f01038fd44a%40googlegroups.com.

Paul Walsh

unread,
Feb 10, 2020, 3:36:27 AM2/10/20
to cgr...@googlegroups.com

Barry O'shaughnessy

unread,
Feb 10, 2020, 3:51:02 AM2/10/20
to CGRateS
OK seems the problem is how I spell it..


{
"id":"0",
"jsonrpc":"2.0",
"method":"APIerSv2.GetAccount",
"params":[
{
"tenant":"cgrates.org", 
"Account":"1001",
"id":58
}]
,"id":58
}



On Monday, February 10, 2020 at 1:26:39 PM UTC+7, Barry O'shaughnessy wrote:

Barry O'shaughnessy

unread,
Feb 10, 2020, 4:08:42 AM2/10/20
to CGRateS
That new link to the documentation did it, thanks Paul. Also had a poke around the system and found  CGRates.postman_collection_v2.1.json which lists some of the correct spellings and now I'm cooking with gas.


On Monday, February 10, 2020 at 1:26:39 PM UTC+7, Barry O'shaughnessy wrote:

Teofil Voivozeanu

unread,
Feb 10, 2020, 6:44:34 AM2/10/20
to CGRateS
Hi Barry,

You have quite a few options to do this : 
1) One of them is to use our custom tool cgr-console to access data 
cgr> help accounts

Usage: accounts Tenant="" AccountIDs=null Offset=0 Limit=0 Filter=null 

2) A member from the community adds templates for Postman to send API to CGRateS. 
https://github.com/cgrates/cgrates/tree/master/data/postman/Voiceland
3) You can send the API through telnet :
{"method":"APIerSv2.GetAccounts","params":[{"Tenant":"cgrates.org","AccountIDs":["1001"],"Offset":0,"Limit":0,"Filter":null}],"id":0}
To see al available API's in CGRateS please check : 
https://godoc.org/github.com/cgrates/cgrates/apier/v1
https://godoc.org/github.com/cgrates/cgrates/apier/v2

Thanks,
TeoV

Barry O'shaughnessy

unread,
Feb 11, 2020, 3:01:20 AM2/11/20
to CGRateS
Using cgr-console via sheel_exec is working well thanks. Is there anyway to list tenants on the system?

Teofil Voivozeanu

unread,
Feb 11, 2020, 3:52:45 AM2/11/20
to CGRateS
Hi Barry,

Tenant is something that you must be aware of it. In CGRateS it acts as a filter.

Thanks,
TeoV

Michael Klimenko

unread,
Jul 5, 2020, 7:45:52 AM7/5/20
to CGRateS
Hello Guys,
Sorry, but what exactly has changed about the API ?
I am trying but nothing works:

Testing Telnet to port 2012:
######################################
T 2020/07/05 14:36:33.271449 172.21.0.1:42450 -> 172.21.0.3:2012 [AP] #90
{"method":"APIerSv2.GetAccounts","params":[{"Tenant":"cgrates.org","AccountIDs":["1001"],"Offset":0,"Limit":0,"Filter":null}],"id":0}.

##
T 2020/07/05 14:36:33.271754 172.21.0.3:2012 -> 172.21.0.1:42450 [AP] #92
{"id":0,"result":null,"error":"rpc: can't find service APIerSv2.GetAccounts"}

Testing HTTP to port 2080:
##########################################################################
T 2020/07/05 14:37:14.609423 10.224.248.30:60092 -> 172.21.0.3:2080 [AP] #237
POST /jsonrpc HTTP/1.1.
Connection: keep-alive.
Content-Length: 153.
Accept-Language: en-IL,en-US;q=0.9,en;q=0.8,he;q=0.7,ru;q=0.6.
.
{
  "id":"0",
  "jsonrpc":"2.0",
  "method":"APIerSv2.GetAccount",
  "params":[
    {
      "Tenant":"cgrates.org",
      "Account":"1001"
    }
  ]
}
##
T 2020/07/05 14:37:14.609989 172.21.0.3:2080 -> 10.224.248.30:60092 [AP] #239
HTTP/1.1 200 OK.
Content-Type: application/json.
Date: Sun, 05 Jul 2020 11:37:14 GMT.
Content-Length: 79.
.
{"id":"0","result":null,"error":"rpc: can't find service APIerSv2.GetAccount"}

############################

Testing with the console :
golan@ppcc-cgr-ptk-node-01:~/cgrates_docker/env/ppcc-cgr-ptk-node-01$ docker run --net=container:rals gitlab-ptk.gt.local:5005/cgr-console:d77f5abea081 accounts
Error executing command: rpc: can't find service APIerSv2.GetAccounts

trace shows
########
T 2020/07/05 14:41:31.381599 127.0.0.1:42136 -> 127.0.0.1:2012 [AP] #230
{"method":"APIerSv2.GetAccounts","params":[{"Tenant":"","AccountIDs":null,"Offset":0,"Limit":0,"Filter":null}],"id":0}

##
T 2020/07/05 14:41:31.381715 127.0.0.1:2012 -> 127.0.0.1:42136 [AP] #232
{"id":0,"result":null,"error":"rpc: can't find service APIerSv2.GetAccounts"}


The config is the same as we always used: rals with http module on port 2080. Perhaps something is changed in regards to http module and where apier is serving now ?
Please assist, where am I wrong ?

Thanks,
Michael

DanB

unread,
Jul 5, 2020, 7:51:25 AM7/5/20
to cgr...@googlegroups.com

Hi Michael,


You need to specifically enable the apiers in configuration:

https://github.com/cgrates/cgrates/blob/v0.10/config/config_defaults.go#L811


DanB

--
You received this message because you are subscribed to the Google Groups "CGRateS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cgrates+u...@googlegroups.com.

Michael Klimenko

unread,
Jul 5, 2020, 8:14:32 AM7/5/20
to CGRateS
Hello Dan,
Thanks for the prompt reply !
I did enable apier, but I still get the same result, are there any changes in ports also ?
I expect HTTP on port 2080 to answer, is that correct ?
To unsubscribe from this group and stop receiving emails from it, send an email to cgr...@googlegroups.com.

Michael Klimenko

unread,
Jul 5, 2020, 8:35:25 AM7/5/20
to CGRateS
RALs loading log looks like JSON-RPC is started on port 2080:
rals          | 2020/07/05 15:31:09 CGRateS <rals> [INFO] <CoreS> starting version <CGR...@v0.11.0~dev-20200701160431-d77f5abea081><go1.13.5>
rals          | 2020/07/05 15:31:09 rpc.Register: method "Call" has 4 input parameters; needs exactly three
rals          | 2020/07/05 15:31:09 rpc.Register: method "Call" has 4 input parameters; needs exactly three
rals          | 2020/07/05 15:31:09 rpc.Register: method "Call" has 4 input parameters; needs exactly three
rals          | 2020/07/05 15:31:09 rpc.Register: method "Call" has 4 input parameters; needs exactly three
rals          | 2020/07/05 15:31:09 rpc.Register: method "Call" has 4 input parameters; needs exactly three
rals          | 2020/07/05 15:31:09 CGRateS <rals> [WARNING] WARNING: missing TLS certificate/key file!
rals          | 2020/07/05 15:31:09 CGRateS <rals> [WARNING] WARNING: missing TLS certificate/key file!
rals          | 2020/07/05 15:31:09 CGRateS <rals> [WARNING] WARNING: missing TLS certificate/key file!
rals          | 2020/07/05 15:31:09 CGRateS <rals> [INFO] <HTTP> enabling handler for JSON-RPC
rals          | 2020/07/05 15:31:09 CGRateS <rals> [INFO] <HTTP> enabling handler for WebSocket connections
rals          | 2020/07/05 15:31:09 CGRateS <rals> [INFO] <HTTP> start listening at <:2080>
rals          | 2020/07/05 15:31:09 rpc.Register: method "Call" has 4 input parameters; needs exactly three
rals          | 2020/07/05 15:31:09 CGRateS <rals> [INFO] <CoreS> starting <ChargerS> subsystem
rals          | 2020/07/05 15:31:09 CGRateS <rals> [INFO] <ServiceManager> Starting CGRateS Scheduler.
rals          | 2020/07/05 15:31:09 rpc.Register: method "Call" has 4 input parameters; needs exactly three
rals          | 2020/07/05 15:31:09 CGRateS <rals> [INFO] Starting CGRateS GOB server at <:2013>.
rals          | 2020/07/05 15:31:09 CGRateS <rals> [INFO] Starting CGRateS JSON server at <:2012>.
rals          | 2020/07/05 15:31:09 rpc.Register: method "SetMaxComputedUsage" has 2 input parameters; needs exactly three
rals          | 2020/07/05 15:31:09 rpc.Register: method "Call" has 4 input parameters; needs exactly three
rals          | 2020/07/05 15:31:09 CGRateS <rals> [INFO] <Scheduler> processing 0 action plans
rals          | 2020/07/05 15:31:09 CGRateS <rals> [INFO] <Scheduler> queued 0 action plans


Now, when I try HTTP 2080 with different methods: 
{"id":"0","result":null,"error":"rpc: can't find service APIerSv2.GetAccount"}
{"id":"0","result":null,"error":"rpc: can't find service APIerSv2.GetAccounts"}
{"id":"0","result":null,"error":"rpc: can't find service APIerSv1.GetAccount"}
{"id":"0","result":null,"error":"rpc: can't find service APIerSv1.GetAccounts"}

What am I missing?

DanB

unread,
Jul 5, 2020, 8:36:15 AM7/5/20
to cgr...@googlegroups.com

Hi Michael,


Can you please post your configuration file?


DanB

To unsubscribe from this group and stop receiving emails from it, send an email to cgrates+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cgrates/7eedd89f-3f85-4063-a28d-1e27d485c025o%40googlegroups.com.

Michael Klimenko

unread,
Jul 5, 2020, 11:09:52 AM7/5/20
to CGRateS

{
       
"general": {
               
"node_id": "*env:CGR_SERVICE",
               
"default_request_type": "*prepaid",
               
"default_tenant": "golant",        
               
"default_timezone": "UTC",          
               
"connect_attempts": 10,            
               
"reconnects": 3,                    
               
"connect_timeout": "3s",            
 
},


       
"data_db": {                                          
               
"db_type": "*env:DATADB_TYPE",                
               
"db_host": "*env:DATADB_HOST",                
               
"db_port": *env:DATADB_PORT,                  
               
"db_name": "*env:DATADB_NAME",                
 
},


       
"stor_db": {                                          
               
"db_type": "*env:STORDB_TYPE",                
               
"db_host": "*env:STORDB_HOST",                
               
"db_port": *env:STORDB_PORT,                  
               
"db_name": "*env:STORDB_NAME",                
               
"db_user": "*env:STORDB_USER",                
               
"db_password": "*env:STORDB_PASS",            
 
"max_idle_conns": 0,
               
"conn_max_lifetime": 7200,
       
},


       
"listen": {
               
"rpc_json": "*env:LISTEN_RPC_JSON",
               
"rpc_gob": "*env:LISTEN_RPC_GOB",
               
"http": "*env:LISTEN_HTTP",
       
},


       
"http": {                                              
 
},


       
"cache":{
   
"attribute_profiles": {"limit": 0, "ttl": "", "static_ttl": false, "precache": false},
                 
"attribute_filter_indexes" : {"limit": 0, "ttl": "", "static_ttl": false},
       
},


       
"rpc_conns": {
               
"rals_address_pool": {
                       
"strategy": "*first",
                       
"conns": [{"address": "*env:RALS_ADDR","transport":"*json"}],


               
},
               
"cdrs_address_pool": {
                       
"strategy": "*first",
                       
"conns": [{"address": "*env:CDRS_ADDR","transport":"*json"}],


               
},
               
"sessions_address_pool": {
                       
"strategy": "*first",
                       
"conns": [{"address": "*env:SESS_ADDR","transport":"*json"}],


               
},
               
"chargers_address_pool": {
                       
"strategy": "*first",
                       
"conns": [{"address": "*env:RALS_ADDR","transport":"*json"}],


               
},
               
"attributes_address_pool": {
                       
"strategy": "*first",
                       
"conns": [{"address": "*env:RALS_ADDR", "transport": "*json"}],


               
},
               
"session_replication_address_pool": {
                       
"strategy": "*first",
                       
"conns": [{"address": "*env:SESS_REPL_ADDR","transport":"*json"}],


               
},
               
"caches_address_pool": {
                       
"strategy": "*first",
                       
"conns": [{"address": "*env:RALS_ADDR", "transport": "*json"}],


               
},
               
"scheduler_conns": {
                       
"strategy": "*first",
                       
"conns": [{"address": "*env:SCHD_ADDR","transport":"*json"}],


               
},
       
},


       
"apier": {
               
"enabled": true,
               
"caches_conns":["caches_address_pool"],
               
"scheduler_conns": ["scheduler_conns"],
               
"attributes_conns": ["attributes_address_pool"],
       
},
 
"schedulers": {
               
"enabled": true,
               
"cdrs_conns": ["cdrs_address_pool"],
       
},


       
"chargers": {
               
"enabled": true,


       
},


       
"rals": {
               
"enabled": true,
       
}
}
 

DanB

unread,
Jul 5, 2020, 11:16:42 AM7/5/20
to cgr...@googlegroups.com

Michael,


For some reason I cannot find apiers enabled in your config ;).


DanB

To unsubscribe from this group and stop receiving emails from it, send an email to cgrates+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cgrates/07d082d4-95e8-40a7-aa44-62a70e4dbed9o%40googlegroups.com.

Michael Klimenko

unread,
Jul 5, 2020, 11:19:03 AM7/5/20
to CGRateS
Hi, Dan
Isn't that enough ?
 "apier": {
                
"enabled": true,

Dan B

unread,
Jul 5, 2020, 12:57:02 PM7/5/20
to cgr...@googlegroups.com
Hi Michael,

I would compare with the link I have sent you.

DanB

To unsubscribe from this group and stop receiving emails from it, send an email to cgrates+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cgrates/26b0c8aa-6aec-477d-a9dc-7ac7c93ebcc9o%40googlegroups.com.

Michael Klimenko

unread,
Jul 5, 2020, 5:26:13 PM7/5/20
to CGRateS
My bad, so it was the letter "s".
Instead of "apier", should be "apiers" ...
It is working now !

I see that also old methods names still work, is that going to be deprecated at some point ?


Thanks,




On Sunday, July 5, 2020 at 7:57:02 PM UTC+3, DanB wrote:
Hi Michael,

I would compare with the link I have sent you.

DanB

Dan B

unread,
Jul 5, 2020, 5:40:12 PM7/5/20
to cgr...@googlegroups.com
Hey Michael,

Yeah, old methods will be deprecated (if not the whole APIer 😉).

DanB

To unsubscribe from this group and stop receiving emails from it, send an email to cgrates+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cgrates/74eae53f-52d2-4624-a28e-8242385192dbo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages