Why is my POST with cURL not returning JSON correctly?
<p>In PHP, I'm trying to retrieve the url for a specific page in DocuSign that constantly refreshes. The POST to retrieve this url is in the form:</p>

<pre><code>POST http://demo.docusign.net/restapi/{apiVersion}/accounts/{accountId}/envelopes/{envelopeId}/views/recipient
</code></pre>

<p>This should return a json file in the form:</p>

<pre><code>{
  "url": "example.example.com"
}
</code></pre>

<p>However, I am extremely new to using PHP and POST methods and don't believe I'm doing this correctly. The API explorer for this method in particular is <a href="https://apiexplorer.docusign.com/#/?categories=Envelopes&amp;tags=EnvelopeViews&amp;operations=createRecipient&amp;mode=basic" rel="nofollow">here</a>. I am using cURL methods to make this request. Here is my code (<code>$recipient</code>,<code>$account_id</code>,<code>$access_token</code> are found accurately within another file):</p>

<pre><code>$url = "http://demo.docusign.net/restapi/v2/accounts/$account_id
         /envelopes/$envelope_id/views/recipient";

$body = array("returnUrl" =&gt; "http://www.docusign.com/devcenter",
              "authenticationMethod" =&gt; "None",
              "email" =&gt; "$recipient",
              "userName" =&gt; "$recipient");

$body_string = json_encode($body);

$header = array(
    'Accept: application/json',
    'Content-Type: application/json',
    'Content-Length: '.strlen($body_string),
);

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body_string);

$json_response = curl_exec($curl);
$response = json_decode($json_response, true);

var_dump($response);
</code></pre>

<p>I am able to get the correct return on the API explorer, but not when making the request with PHP. I believe this is due to the fact that I am not incorporating the <code>$header</code> or <code>$body</code> correctly, but at this point I am just not sure.</p>

<p><strong>ADDED:</strong> This is the raw output for the request when correctly running the method on the API Explorer:</p>

<p>Accept: application/json<br>
Accept-Encoding: gzip,deflate,sdch<br>
Accept-Language: en-US,en;q=0.8,fa;q=0.6,sv;q=0.4<br>
Cache-Control: no-cache<br>
Origin: <a href="https://apiexplorer.docusign.com" rel="nofollow">https://apiexplorer.docusign.com</a><br>
Referer: <a href="https://apiexplorer.docusign.com/" rel="nofollow">https://apiexplorer.docusign.com/</a><br>
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5)<br> AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36<br>
Authorization: Bearer fGehcK7fkRvFguyu/7NGh01UUFs=<br>
Content-Length:<br>
Content-Type: application/json<br></p>

<p>This is the JSON request being formed in my code:</p>

<pre><code>{
  "returnUrl":"http:\/\/www.docusign.com\/devcenter",
  "authenticationMethod":"Password",
  "email":"example@example.com",
  "userName":"example@example.com",
  "clientUserId":"4c6228f4-fcfe-47f9-bee1-c9d5e6ab6a41",
  "userId":"example@example.com"
}
</code></pre>