Skip to Content
Menu
This question has been flagged
2 Replies
652 Views

I want to give the public user access to some data.


But if I use the jsonRPC without credentials I always get a Odoo Session Expired although the permissions would allow my model to be read from a public user.



What can I do to receive data as a public user?

Avatar
Discard
Author Best Answer

But I want to make my question more precise:

Is it possible to the this jsonrpc working with a session_id of a public user? (not logged in)




import requests

import json


url = "https://73515246-18-0-all.runbot185.odoo.com/web/dataset/call_kw/forum.post/web_search_read"


payload = json.dumps({

"id": 1,

"jsonrpc": "2.0",

"method": "call",

"params": {

"model": "res.partner",

"method": "web_search_read",

"args": [],

"kwargs": {

"specification": {

"name": {}

},

"order": "name",

"domain": [],

"context": {

"uid": None

}

}

}

})

headers = {

'Content-Type': 'application/json',

'Cookie': 'session_id=clfQpy5iv6hb5cq9VacECtum8t2bPZ1OhBwZ5AEr9ya_4xj-I84eUSrEJKSOLhCy9JcXhpOq8QSmusQ3S08M'

}


response = requests.request("GET", url, headers=headers, data=payload)


print(response.text)


Avatar
Discard
Best Answer

Just create a publicly accessible controller and use as any REST.
For example, the below GET endpoint can be accessed by just visiting /thank_you.

from odoo import http

class ThankYouController(http.Controller):

​@http.route('/thank_you', auth='public', methods=['GET'], type='http')

​def thank_you(self, **kwargs):

​return "THANK YOU"

Avatar
Discard
Author

Thanks, but the background I need this is because I want to use websearchread an standard OWL method to retrieve data. But If the user is not logged in it does not work. I want to use Owl2 in the frontend which works perfectly with websearchread but as it's also can be used by not logged in users it also has to work with not logged in users.
The core problem can be replicated by creating a json request without authentication. It would be interesting if there is standard way to do this. I had to override some very basic functionality which I want to avoid.

Related Posts Replies Views Activity
0
Mar 24
550
2
Sep 15
6001
1
Apr 23
2312
1
May 25
690
0
Mar 25
347