title: POST encripted request with JSON body on R
body: <p>I am trying to use R to post an encrypted request to an <a href="https://bitso.com/api_info#creating-and-signing-requests" rel="nofollow noreferrer">API</a>.</p>
  
  <p>Specifically the <strong>/v3/orders/</strong> request.</p>
  
  <p>It requires the use of an API <code>key</code> and <code>secret</code>, as well as an increasing <code>nonce</code>.</p>
  
  <p>Using <code>openssl</code>, <code>jsonlite</code> and <code>httr</code> libraries:</p>
  
  <p>The body has to be JSON encoded:</p>
  
  <pre><code>book&lt;-"btc_eth"
  side&lt;-"sell"
  major&lt;-"0.1"
  price&lt;-"100"
  type&lt;-"limit"
  
  Payload&lt;-toJSON(data.frame(book=book,side=side,major=major,price=price,type=type))
  </code></pre>
  
  <p>It also requires an authorization header constructed with an <strong>sha256</strong> encrypted <code>signature</code>.</p>
  
  <pre><code>N&lt;-NONCE() # "1503033312"
  
  method&lt;-"POST"
  
  Path&lt;-"/v3/orders/"
  
  Signature&lt;-sha256(paste0(N,method,Path,Payload),secret)
  
  header&lt;-paste0("Bitso ",key,":",N,":",Signature)
  </code></pre>
  
  <p>Finally the request should look like this:</p>
  
  <pre><code>url&lt;-"https://api.bitso.com/v3/orders/"
  
  r&lt;-POST(url, body = Payload, add_headers(Authorization=header))
  </code></pre>
  
  <p>I have been able to post requests with an empty payload to this API before, but this call sends unsupported media type error, something about the way I'm JSON encoding the paylod is causing this. </p>
  
  <p>There's Ruby and PHP examples on how to place this request <a href="https://bitso.com/api_info#creating-and-signing-requests" rel="nofollow noreferrer">here</a>.</p>