I not sure what you mean by "it is not working" but there are many problems with this code:
@request.restful() def api(): response.view = 'generic.'+request.extension def GET(search): pass clients = db(db.auth_user).select(db.auth_user.api_key) t = db.t_tests_results def POST(**post_params): for client in clients: if client.api_key == post_params.api_key: return t.validate_and_insert(post_params.test, post_params.f_platform, post_params.f_device, post_params.f_steps, post_params.f_matches, post_params.f_missmatches, post_params.f_missing) else: raise HTTP(400) 1) it should return locals() 2) there should not be local variables other than the GET, POST, etc. methods. 3) Should not loop over clients to validate the API key. 4) **post_params should really specify what those parameters could be or you should validate them somehow. 5) You should need a view for an API (although you can have one). Here is what I would write: @request.restful() def api(): response.view = 'generic.'+request.extension def GET(search): return 'false' def POST(**post_params): client = db.auth_user(api_key=post_params.api_key) if not client: raise HTTP(404) t = db.t_tests_results d = t.validate_and_insert(**t._filter_fields(post_params)) return response.json(d) return locals() On Saturday, 1 February 2014 09:56:36 UTC-6, Avi A wrote: > > > > On Thursday, January 30, 2014 12:30:52 PM UTC+2, Avi A wrote: >> >> Hi, >> I am trying something like that: >> #on one local script instance: >> import requests >> >> test_params = {'api_key': 'api_key', 'test': 'test', 'f_platform': >> 'platform', 'f_device': 'device', 'f_steps': '10', >> 'f_matches':'7', 'f_missmatches': '3', 'f_missing': '0'} >> r = requests.post('http://127.0.0.1:8000/qatests/api', >> params=test_params) >> >> #and the api function: >> >> @request.restful() >> def api(): >> response.view = 'generic.'+request.extension >> def GET(search): >> pass >> clients = db(db.auth_user).select(db.auth_user.api_key) >> t = db.t_tests_results >> def POST(**post_params): >> for client in clients: >> if client.api_key == post_params.api_key: >> return t.validate_and_insert(post_params.test, >> post_params.f_platform, >> post_params.f_device, >> post_params.f_steps, >> post_params.f_matches, >> post_params.f_missmatches, >> post_params.f_missing) >> else: >> raise HTTP(400) >> >> It's not working... Any help? >> Thanks. >> >> >> >> >> >> >> >> >> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.