Example of JSON-RPC call

1,062 views
Skip to first unread message

Tristian Paul

unread,
Dec 4, 2012, 5:58:31 PM12/4/12
to try...@googlegroups.com
How would you make a json rpc call, the wiki has examples but for the XML RPC protocol.

Regards

zodman

unread,
Dec 4, 2012, 7:30:07 PM12/4/12
to try...@googlegroups.com
2012/12/4 Tristian Paul <tristia...@gmail.com>:
> How would you make a json rpc call, the wiki has examples but for the XML
> RPC protocol.
>
> Regards
>
> --
> --
> try...@googlegroups.com mailing list
>
>
>

this can work http://code.google.com/p/tryton/wiki/CodeSnippets#tryton_jsonrpc_client_for_create_a_database

--
Andres Vargas
www.zodman.com.mx

Jose Patricio Villarerreal

unread,
Jul 26, 2013, 4:30:24 PM7/26/13
to try...@googlegroups.com
Sorry for my poor knowledge, am a newbie to Tryton.  We are OpenERP Partners and we are exploring the idea of using Tryton as a backend for a web page. We are using Tryton 2.8 and we were trying to use the XML-RPC protocol but there's a kid of bug, any how.

We saw the the example you are putting  on the link, we can get the database list and create a new database, but how we will do it to make a call to a certain module with a certain user and password?

Appreciate your help :)

Best Regards,
JPV

Nicolas Évrard

unread,
Jul 26, 2013, 4:37:57 PM7/26/13
to try...@googlegroups.com
* Jose Patricio Villarerreal [2013-07-26 18:30 +0200]:
>Sorry for my poor knowledge, am a newbie to Tryton. We are OpenERP
>Partners and we are exploring the idea of using Tryton as a backend for a
>web page. We are using Tryton 2.8 and we were trying to use the XML-RPC
>protocol but there's a kid of bug, any how.
>
>We saw the the example you are putting on the link, we can get the
>database list and create a new database, but how we will do it to make a
>call to a certain module with a certain user and password?

Did you try the example on

http://code.google.com/p/tryton/wiki/RemoteCalls#XML-RPC_in_Python

If I am not mistaken JSON-RPC should work just like XML-RPC

PS: Please do not top post on this mailing list.

--
Nicolas Évrard

B2CK SPRL
4, rue de Rotterdam
4000 Liège
Belgium
Tel: +32 472 54 46 59
E-mail/Jabber: nicolas...@b2ck.com
Website: http://www.b2ck.com/
signature.asc

Steve Heyns

unread,
Aug 26, 2013, 9:21:55 PM8/26/13
to try...@googlegroups.com
I am having the same issue. I am not exactly sure how that example relates to a JSON-RPC call
I have tried to POSTing the following to localhost:8000/try

{method:"sever.version",id:1,params:[]}

and I receive a 500 internal error as a response. But in the trytond log file there is no errors

I also tried posting this and got the same error ... 
{method:"system.listMethods",id:1,params:[]}

The tryton client works fine in this respect nut how does a trace translate to something to be posted ? Like what does the following translate to ?
INFO:tryton.rpc:common.server.version(None, None)

I would assume that this is translated to :
{method:"common.server.version",id:1,params:['','']}

but it just gives the same 500 error code..

Hellafrustrated atm
Nz

Pierre-Louis Bonicoli

unread,
Aug 27, 2013, 3:25:50 PM8/27/13
to try...@googlegroups.com
On 26/08/2013 23:21, Steve Heyns wrote:
> I have tried to POSTing the following to localhost:8000/try
>
> {method:"sever.version",id:1,params:[]}

Try:
{"method": "system.server.listMethods", "id": 1, "params": [null, null]}

> and I receive a 500 internal error as a response. But in the trytond log
> file there is no errors
[...]
> The tryton client works fine in this respect nut how does a trace translate to something to be posted ? Like what does the following translate to ?
>
> INFO:tryton.rpc:common.server.version(None, None)
>
> I would assume that this is translated to :
> {method:"common.server.version",id:1,params:['','']}

Try:
{"method": "common.server.version", "id":1, "params": [null, null]}

You could use replace "server" by any string or use "common..version".


Here is a Bash script which use "common.server.version" and
"system.server.listMethods":

> #!/bin/bash
> DBNAME=demo2.8
> HOST=https://demo.tryton.org:8000
>
> # Définition du contenu de la requête
> data=$(cat <<DATA
> {"id": 1, "method": "common.server.version", "params": [null, null]}
> DATA
> )
>
> # Envoie de la requête au serveur Tryton
> wget -q -O - --no-http-keep-alive --post-data="$data" \
> --header="Content-Type: text/json" --no-check-certificate \
> $HOST
>
> echo
>
> # Définition du contenu de la requête
> data=$(cat <<DATA
> {"id": 1, "method": "system.server.listMethods", "params": [null, null]}
> DATA
> )
>
> # Envoie de la requête au serveur Tryton
> wget -q -O - --no-http-keep-alive --post-data="$data" \
> --header="Content-Type: text/json" --no-check-certificate \
> $HOST/$DBNAME
>
> echo

The format of JSONRPC query is:
{
"id": id of the request, used by response
"method": name of the call,
"params": [
first parameter,
second parameter,
third parameter,
...
]
}


Requests can be categorized in two ways:
- anonymous calls
- authenticated calls

"common.server.version" and "system.server.listMethods" are anonymous.

In order to authenticate an user, you must perform the anonymous call
"common.server.login(username, password)". If successful, this call
returns user id and a cookie.

User id and cookie are first and second parameters of authenticated
calls. Context is the last parameter of authenticated call, it could be:
- an empty dict
- retrieved with authenticated call:
model.res.user.get_preferences(user_id, cookie, True, {})

An example: model "ir.model", read fields "info", "model", "name" and
"module" records 47 and 71:

> {
> "id": 8,
> "method": "model.ir.model.read",
> "params":
> [
> 1,
> "qdWWyL6guIJrnxTFGaWX7xc6o/BH+QnZbFcgU=",
> [47, 71],
> ["info", "model", "name", "module"],
> {
> "language": "fr_FR", "locale": {
> "date": "%d.%m.%Y", "thousands_sep": "", "grouping": [],
> "decimal_point": ","
> },
> "language_direction": "ltr", "groups": [1], "timezone": null
> }
> ]
> }

In order to manipulate the data, the following calls are available:
model.<modelname>.(search|read|create|write|delete|copy)

--
Pierre-Louis

Steve Heyns

unread,
Aug 27, 2013, 10:14:06 PM8/27/13
to try...@googlegroups.com, pierre-lou...@bioecoforests.com
Hi

Thanks Pierre-Louis, the key bit of information appears to have been the url path must be the database ! Did not see that mentioned anywhere, but those examples are golden. Appreciated..

Nz

Jose Patricio Villarerreal

unread,
Aug 27, 2013, 11:34:07 PM8/27/13
to try...@googlegroups.com, pierre-lou...@bioecoforests.com


Thanks a lot... :)

Steve Heyns

unread,
Aug 28, 2013, 8:34:26 PM8/28/13
to try...@googlegroups.com, pierre-lou...@bioecoforests.com
I am able to translate most calls but I am having issues with these round brackets for this call
INFO:tryton.rpc:model.product.template.search(1, '4d474faa5139490bbae47516eaf23402', [('rec_name', 'ilike', u'%boo%'), ('active', '=', True)], 0, 1000, None, {'language': 'en_US', 'locale': {'date': '%m/%d/%Y', 'thousands_sep': ',', 'grouping': [3, 3, 0], 'decimal_point': '.'}, 'language_direction': 'ltr', 'company_work_time': {'Y': 1920.0, 'M': 160.0, 'd': 8.0, 'w': 40.0}, 'company.rec_name': 'artemis', 'groups': [9, 10, 1, 15, 5, 2, 4, 3, 12, 11, 16, 24, 21, 20, 22, 23, 18, 19, 17, 7, 6, 8, 13, 14], 'employee': None, 'timezone': None, 'company': 1})

Specifically the " [('rec_name', 'ilike', u'%boo%'), ('active', '=', True)]" section is causing me some headaches. Passing in an empty array works fine. but the following [{"active","=",true}] fails. Any idea what the () brackets are supposed to be translated as ?

thanks
Steve


Steve Heyns

unread,
Aug 29, 2013, 2:22:09 AM8/29/13
to try...@googlegroups.com, pierre-lou...@bioecoforests.com
Resolved myself, sb [["active","=",true]] 
Reply all
Reply to author
Forward
0 new messages