2

Trying to use URI library to generate JSON in the proper formate for Eventbrite batch endpoint but not getting the right encoding from URI library.

url = URI.escape('{"method":"GET", "relative_url":"users/me"},{"method":"GET", "relative_url":"users/me/owned_events/"},{"method":"GET", "relative_url":"users/me/owned_events/?page=2"}')

=>%7B%22method%22:%22GET%22,%20%22relative_url%22:%22users/me%22%7D,
%7B%22method%22:%22GET%22,%20%22relative_url%22:%22users/me/owned_events/%22%7D,
%7B%22method%22:%22GET%22,%20%22relative_url%22:%22users/me/owned_events/?page=2%22%7D

This is the require encoding:

%5B+++++%7B%22method%22%3A%22GET%22%2C+%22relative_url%22%3A%22users%2Fme
%22%7D%2C+++++%7B%22method%22%3A%22GET%22%2C+%22relative_url%22%3A
%22users%2Fme%2Fowned_events%2F%22%7D%2C+++++%7B%22method%22%3A%22GET
%22%2C+%22relative_url%22%3A%22users%2Fme%2Fowned_events%2F%3Fpage%3D2%22%7D+%5D
4
  • 1
    These look exactly the same with CGI.escape and CGI.unescape, only the "required encoding" has spaces and newlines. Are you sure this is the source of whatever problem you are experiencing? It might very well not be.. Commented Apr 29, 2016 at 23:42
  • I am sure this is the source as I have tried requests with the required encoding successfully you can try the api here: eventbriteapi.com/v3/batch Commented Apr 29, 2016 at 23:49
  • I can't use the link since I don't have a token. However, I believe you need to send a POST request, not a GET request, so encoding using URI.escape is not something you need to be doing. The URI endpoint should simply be eventbriteapi.com/v3/batch, and you should submit the array of JSONs via POST. Commented Apr 29, 2016 at 23:59
  • Oh, you forgot to enclose your JSON objects in an Array... CGI.escape('[{"method":"GET", "relative_url":"users/me"},{"method":"GET", "relative_url":"users/me/owned_events/"},{"method":"GET", "relative_url":"users/me/owned_events/?page=2"}]') looks much more similar to your desired outcome. Commented Apr 30, 2016 at 0:02

1 Answer 1

3

I believe you forgot to enclose your JSON objects in an array (note the square brackets):

CGI.escape('[{"method":"GET", "relative_url":"users/me"},{"method":"GET", "relative_url":"users/me/owned_events/"},{"method":"GET", "relative_url":"users/me/owned_events/?page=2"}]')

Results in:

%5B%7B%22method%22%3A%22GET%22%2C+%22relative_url%22%3A%22users%2Fme%22%7D%2C%7B%22method%22%3A%22GET%22%2C+%22relative_url%22%3A%22users%2Fme%2Fowned_events%2F%22%7D%2C%7B%22method%22%3A%22GET%22%2C+%22relative_url%22%3A%22users%2Fme%2Fowned_events%2F%3Fpage%3D2%22%7D%5D

Which is the same as your desired outcome, give or take white spaces.

I'm not sure why you're using URI for this, by the way. The URI should simply be eventbriteapi.com/v3/batch as far as I understand. Based on their documentation, it seems like the payload you're sending should be sent to this URI via a POST request. For encoding of payloads you should use CGI or Base64.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.