Using curl and/or httr with streaming API

Alright. First off, I'm not going to be able to give a reprex, but I'd like to describe the situation, and if someone can point me in a direction -something to read, a clue, anything- I'd be grateful.

Thus far, I've read the vignettes for the httr and curl packages several times.

My problem: A financial institution offers an API to query economic/ market data via subscription and in real time via streaming data but I'm having trouble getting any data.

Here is a sketch of the tedium involved:

  1. get some account info using

httr::POST(some_url, with payload of secret login creds) %>% ...parse xml response...

  1. using the returned info from step 1), get 24 hour token using

httr::GET(some_new_url_with) %>% ...parse xml response...


  1. now, using info from steps 1) and 2), I try to get the API to return a raw octet stream as promised by the API documentation, which can apparently be done via GET or POST.

To generate a kosher URL, the query string must be encoded, so using URLencode() I create something that looks like this:

my_url <- "**_myLogin_**%26W%3D**_myToken_**%**_etc_**"

Now, if I simply try to httr::GET(my_url), this fails with the following error

Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
_ invalid 'trim' argument_

Then again, my reading of the httr vignette suggests that maybe it doesn't contemplate streaming info anyway and that I need to be starting with the curl package.

I therefore try the following:

req <- curl::curl_fetch_memory(command_total)


HTTP/1.0 200 OK
Date: Mon 02 Mar 1998 10:20:00 GMT
Server: StreamerServer
Content-type: application/octet-stream
Pragma: no-cache
Cache-Control: no-cache
Accept-Ranges: none
Set-Cookie: NSC_QSPE-BTUNESN02-WJQ2-80-c01=ffffffff098yyyy04zz25dxxx58455e4422;expires=Sat, 02-Dec-2017 17:27:06 GMT;path=/;httponly

Whoa! It looks like I got something- including a 200 status code.

but, there's no req$content is raw(0)

So, I'm quite stuck as to how to tackle this next.

Can you share some of your code that you are using to access the API? Without your code, it's hard to see exactly what you are doing, and where the error occurs. It seems like you may just be passing a number, where it needs formatting with the trim argument. This thread may help:

Thank you for your response.

Unfortunately, I can't really give something reproducible given that the URL contains a lot of sensitive information, and yes, based on that link you provided and generally googling the error, it's almost certainly related to the url encoding.

But it's odd to me that I don't get a similar error from curl::curl_fetch_xxx, and in fact I get a 200 status code, making me think that that's the right track, but that there's something I'm failing to do with the connection object.

With all that said, below is a before-and-after of the url I'm using, with sensitive info redacted, but with otherwise identical syntax:

not url encoded:

url encoded, as required by the API documentation: