title: R httr GET request 400 error GDAX
body: <p>I am trying to hit <strong>GDAX</strong> using <code>R</code> and getting the following issue. How do I solve for the issue using <code>httr</code>.</p>
  
  <pre><code>Response [https://api-public.sandbox.gdax.com/accounts]
    Date: 2017-12-07 20:30
    Status: 400
    Content-Type: application/json; charset=utf-8
    Size: 53 B
  </code></pre>
  
  <p>Below is my code. Please note that the issue exists only with <code>httr</code> package and not with <code>RCurl</code> (code provided in appendix)</p>
  
  <pre><code>library(digest)
  library(httr)
  library(RCurl) # for base64Decode
  
  url &lt;- "https://api-public.sandbox.gdax.com/accounts"
  secret &lt;- # API secret from GDAX sandbox
  api.key &lt;- # API key from GDAX sandbox
  passphrase &lt;- # API passphrase from GDAX sandbox
  
  timestamp &lt;- format(as.numeric(Sys.time()), digits=13) # create nonce
  key &lt;- base64Decode(secret, mode="raw") # encode api secret
  what &lt;- paste0(timestamp, "GET", req.url)
  sign &lt;- base64Encode(hmac(key, what, algo="sha256", raw=TRUE))
  
  connector &lt;- list(url = url, nonce = timestamp, signature = sign))
  
  GET(url=connector$url,
    add_headers(
      'CB-ACCESS-KEY'=api.key,
      'CB-ACCESS-SIGN'=connector$signature,
      'CB-ACCESS-TIMESTAMP'=connector$nonce,
      'CB-ACCESS-PASSPHRASE'=passphrase,
      'Content-Type'='application/json'
    )
  )
  </code></pre>
  
  <p>If however, I use <code>RCurl</code> then I am able to get a response content using the following code.</p>
  
  <pre><code>httpheader &lt;- list('CB-ACCESS-KEY'=api.key,
    'CB-ACCESS-SIGN'=sign,
    'CB-ACCESS-TIMESTAMP'=timestamp,
    'CB-ACCESS-PASSPHRASE'=passphrase,
    'Content-Type'='application/json')
  
  connector &lt;- list(url = url, header = httpheader)
  
  getURLContent(url = connector$url,
    curl=getCurlHandle(useragent="R"),
    httpheader=connector$header)
  </code></pre>