-1

I got POST request from API. I checked content-type, it's x-www-form-urlencoded, but body request also contains JSON. How can I parse from JSON in hash?

Parameters of request in console: Screenshot || Parameters: {"vpbx_api_key"=>"etxojfklr6nue6tl627pn5sdi0koov7t", "sign"=>"ad0c49034c8d83a7d7f1b433afc2ed5a9aa08d933dba3724062aed0c3d1a79bb", "json"=>"{\"entry_id\":\"MjYyNjQ2NzM1Njo0Mg==\",\"call_id\":\"MToxMDAxNDAzOTo0Mjo4Mjc2NzEzMzk=\",\"timestamp\":1485939839,\"seq\":2,\"call_state\":\"Disconnected\",\"location\":\"abonent\",\"from\":{\"number\":\"79268220697\",\"taken_from_call_id\":\"MToxMDAxNDAzOTo0Mjo4Mjc2NzEwOTA6MQ==\"},\"to\":{\"extension\":\"2\",\"number\":\"79154612023\",\"line_number\":\"74953749768\"},\"disconnect_reason\":1100}"}

1 Answers1

1

If you want to keep the form encoded that way, you will have the parameters in the params collection. That means you could be parsing that JSON doing something as:

def my_method_to_process_the_post
    parsed = JSON.parse params[:json]
end

'json' is the key for the json that you are receiving in the payload.

For historical evolution of JSON parsing you may want to check this thread.

Community
  • 1
  • 1
Jacob
  • 1,886
  • 2
  • 25
  • 40