0

I'm trying to do a GET request using httr library trough the GET() method with parameters url and query as follows:

r <- GET("https://www.edx.org/api/v1/catalog/search", query = list('page'=page, 'page_size'=params3[[1]], 'partner'=params3[[2]], 
                                                                'hidden'=params3[[3]], 'content_type[]'=params3[[4]], 
                                                                'content_type[]'=params3[[5]], 'featured_course_ids'= params3[[6]], 
                                                                'featured_programs_uuids'=params3[[7]]))

However, when the request is done the URL generated goes like this:

https://www.edx.org/api/v1/catalog/search?page=1&page_size=9&partner=edx&hidden=0&content_type%5B%5D=courserun&content_type%5B%5D=program&featured_course_ids=course-v1%253AAdelaideX%2BProject101x%2B1T2017%252Ccourse-v1%253AMicrosoft%2BDAT222x%2B4T2017%252Ccourse-v1%253AUCSanDiegoX%2BParenting101x%2B2T2017%252Ccourse-v1%253AMicrosoft%2BDEV276x%2B4T2017%252Ccourse-v1%253AW3Cx%2BJS.0x%2B3T2017%252Ccourse-v1%253AIDBx%2BIDB10.1x%2B3T2017&featured_programs_uuids=98b7344e-cd44-4a99-9542-09dfdb11d31b%252Cbe3e00d2-0680-4771-aea5-1fa0dc8ada2a%252C482dee71-e4b9-4b42-a47b-3e16bb69e8f2%252Ca015ce08-a727-46c8-92d1-679b23338bc1%252C8ac6657e-a06a-4a47-aba7-5c86b5811fa1%252Cd220390a-7506-4961-9828-e3594f60a925

The problem is on params "content_type[]" specifically on the characters '[' and ']' because at the url is send as its UTF-8 encode which generates an error on the request because that encode turns the URL invalid for request.

I tried using backslash ('\') but the error keeps there. Any suggestions or clue on how to solve it?

Esteban Sierra
  • 61
  • 1
  • 10
  • `%5B%5D` isn't UTF-8 encoding. It's specifically called [URL Encoding](https://www.w3schools.com/tags/ref_urlencode.asp). Are you sure that's what is causing the problem? It seem odd that any web server wouldn't recognize those escape sequences. It would be nice if you provided a [reproduicble example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – MrFlick Nov 09 '17 at 21:57
  • where are you passing in your authentication token? – hrbrmstr Nov 09 '17 at 22:00
  • Yes I'm sure @MrFlick . If I try to do the request manually using the url as "content_type[]=..." I get a Status Code 200 but if I try manually using the URL Encoding "content_type%5B%5D=..." I get a Status Code 503 (Service Unavailable) – Esteban Sierra Nov 10 '17 at 03:22
  • The problem was the URL base I was using was already URL Encoded, so after using the GET() it URL Encoded again. – Esteban Sierra Nov 14 '17 at 13:10

0 Answers0