This question has been flagged
1 Reply
5930 Views

Hello,

I am trying to remove this parameter to this jsonrpc resultjsonrpc result

{

  "jsonrpc": "2.0",

  "result": {

    "source": "webhook",

    "speech": "hello my name is shubham",

    "displayText": "hello testing"

  }

  "id": "f2f0cca0-1f91-4e8f-b264-74e30dc457e9"

}

i need simple one object result like:

{

  "speech": "hello my name is shubham",

  "displayText": "hello testing",

  "source": "webhook"

}


so please help me with additional parameters


here is my controller code

  @ http.route ('/ userappoint / webhook_test /', type = 'json', auth = 'public', method = ['POST'], csrf = False, website = True)

    def webhook_test (self, ** kw):

      response = {

            'speech': 'hello my name is shubham',

            'displayText': 'hello testing',

            'source': 'webhook'

        }

        return response


Avatar
Discard

You should format your question with proper coding syntax

Author

here is my Code :

@ http.route ('/ userappoint / webhook_test /', type = 'json', auth = 'public', method = ['POST'], csrf = False, website = True)

def webhook_test (self, ** kw):

response = {

'speech': 'hello my name is shubham',

'displayText': 'hello testing',

'source': 'webhook'

}

return response

how I remove additional JSON-RPC parameters in result

Did you Find any Solutions to Resolve this?

Best Answer

The wrapper is defined in the method _json_response of class JsonRequest.

You can rewrite this method for the object "request" for your route only :

from odoo.http import request, JsonRequest, Response

from odoo.tools import date_utils

...

def alternative_json_response(self, result=None, error=None):

  if error is not None:

      response = error

  if result is not None:

      response = result

  mime = 'application/json'

  body = json.dumps(response, default=date_utils.json_default)

  return Response(

    body, status=error and error.pop('http_status', 200) or 200,

    headers=[('Content-Type', mime), ('Content-Length', len(body))]

  )

class YourController(http.Controller):

    ...

    @http.route ('/userappoint/webhook_test/', type = 'json', auth = 'public', method  = ['POST'], csrf = False, website = True)

    def webhook_test (self, ** kw):

       response = {

            'speech': 'hello my name is shubham',

            'displayText': 'hello testing',

            'source': 'webhook'

        }

        request._json_response = alternative_json_response.__get__(request, JsonRequest)

        return response    



Avatar
Discard

just add after ...... from odoo.tools import date_utils
import json

everything is fine.

I want to do it on odoo 16.0