Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
4628 Vistas

What am i doing wrongly with api code?

Every thing works well with Postman api test but I keep having session expired each time i called get controller function on Android App.

I always get a valid session id when authenticating user on ..... https://127.0.0.1/web/session/authenticate

I need guide please.

### My Code Below:###

from odoo import http

from odoo.http import request


class FieldWorker(http.Controller):
# Update Controller

@http.route('/update_worker', type='json', auth='user')

def update_worker(self, **rec):

    if request.jsonrequest:

        if rec['id']:

            fieldworker = request.env['field.workers'].search([('id', '=', rec['id'])])

            if fieldworker:

                fieldworker.write(rec)

            args = {'success': True, 'message': 'Fieldworker Updated'}

    return args


# Get Controller

@http.route('/get_fieldworkers', type='json', auth='user')

def get_fieldworkers(self):

    fieldworker_rec = request.env['field.workers'].search([])

    fieldworkers = []

        for rec in fieldworker_rec:

            vals = {

                'id': rec.id,

                'name': rec.name,

                'community': rec.community,

                'latitudes': rec.latitudes,

                'longitudes': rec.longitudes,

                'team_ids': rec.team_ids,

            }

            fieldworkers.append(vals)

        data = {'status': 200, 'response': fieldworkers, 'message': 'All Fieldworkers Fetched'}               return data

Avatar
Descartar

Do you've got a proxy, like nginx?

Do you've got more than one database? and do you filter the database somehow?

Autor

@ Blanco,

1. Yes, I use nginx

2. Yes, I did filter the databases like dbfilter = ^%d$

Mejor respuesta

You need to pass that session id in the header of each request after authentication. I suggest you to open your log and when you attemp to get or post something your log will tell you what is missing

Avatar
Descartar
Autor

@ Abdullah,

I did passed the session id to each request header on the Android App but always get session expired

Publicaciones relacionadas Respuestas Vistas Actividad
5
may 25
8960
0
jul 22
5257
0
jul 21
6851
3
ago 19
5803
3
feb 24
13759