Home Ask Login Register

Developers Planet

Your answer is one click away!

SamAdmit February 2016

how to get the httparty call return something inside an array

[{"Id"=>1015765, "Date"=>"/Date(1468062000000+0100)/", "EventGroupName"=>"Electric Daisy Carnival", "VenueName"=>"Milton Keynes Bowl", "Town"=>"Milton Keynes", "Country"=>"UK", "TicketCount"=>35, "Currency"=>"GBP", "MinPrice"=>79.75, "LayoutId"=>3932, "EventGroupId"=>32347, "VenueId"=>3596}]

I'm getting this response form an api im calling

How do i go about getting the id to use elsewhere in the controller???

Heres my controller

api = HTTParty.get("url here").parsed_response
id = api["Events"]

I have tried sticking [Id] on the end of the id call but that didnt work.



Heres what i tried :)

id = api["Events"].first["Id"]
    results = HTTParty.get("partoneofurl" + id + "parttwoofurl")

 syntax error, unexpected tIDENTIFIER, expecting ')' 

 syntax error, unexpected ')', expecting keyword_end


Marcus Gomes February 2016

The result of the HTTParty call is an array that contains a hash table with the response elements. To access the these values you need first to access the hash table, that is the array's first element and then you can access the values in the hash table. You can do that in this way:

$ api.first["Key"]

Ilya February 2016

As i undestood, you must to extract Id field from response. Try to write like this


Post Status

Asked in February 2016
Viewed 2,784 times
Voted 6
Answered 2 times


Leave an answer

Quote of the day: live life