Reputation: 599
I'm using grape-api and having a problem with making a GET request from my front-end service with encoded query params. This is how my endpoint is set up to receive the params:
params do
requires :event_id, type: String, desc: 'Event id'
requires :tickets, type: Array, desc: 'Array of each ticket data ex: [ {id: "", count: 1 , coupon_code: ""} ]', allow_blank: false do
requires :id, type: String, desc: 'Ticket id'
requires :count, type: Integer, desc: 'Number of tickets to get'
optional :coupon_code, type: String, desc: 'Promocode to apply if any'
end
end
As you can see I'm expecting an event_id param and another array of objects param tickets, and this is how the request URL looks like:
however, grape doesn't seem to understand these encoded query params and I get this exception:
[Exception: event_id is missing, tickets[0][id] is missing, tickets[0][id] is invalid, tickets[0][count] is missing, tickets[0][count] is invalid]
my question is this: is there a way i can tell grape to decode and parse the query params properly? am i missing something here?
Upvotes: 0
Views: 752
Reputation: 41
http://localhost:3000/api/service_fees/calculate?eventId=2xy6rft69azlu2mtppnzb1xe6olzd3f0&tickets[]=%7B%22id%22:%22vohd3y3n25cdgbvi3uzmqhcyie3zi53a%22,%22count%22:2%7D
For the above request URL, the parameter name sent is eventID
whereas the Grape API requires/expects event_id
. Also, the tickets
URL Query String Parameters construction is wrong.
Can you try this instead -- http://localhost:3000/api/service_fees/calculate?eventId=2xy6rft69azlu2mtppnzb1xe6olzd3f0&tickets[0][id] =12&tickets[0][count] =13&tickets[0][coupon_code]=amrrbakry
Upvotes: 0