title: Setting request body for Guzzle 6 put()
body: <p>I am setting the request body incorrectly for these Guzzle put() calls.  I am making get() calls to same API using same token without issue.</p>
  
  <p>The API has a test environment and here is what a successful put call looks like in cURL:</p>
  
  <pre><code>curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic tokenishere=' -d '{ \ 
     "OrganizationCode": "10", \ 
     "EventID": 5524, \ 
     "FunctionID": 321, \ 
     "Description": "Test" \ 
   }' 'https://example.com/api/v1/Functions/10/5524/321'
  </code></pre>
  
  <p>My Guzzle code is</p>
  
  <pre><code>use GuzzleHttp\Psr7;
  use GuzzleHttp\Exception\RequestException;
  
  $client = new \GuzzleHttp\Client(array("base_uri" =&gt; "https://example.com"));
  
  $response = $client-&gt;put("/api/v1/Functions/10/".$_SESSION['eventID'].'/'.$functionID, 
      array(
          'headers'   =&gt; array(
              'token' =&gt; $token,  
              'debug' =&gt; true,            
          ), 
          'body' =&gt; $data
      )
  </code></pre>
  
  <p>I have also tried </p>
  
  <pre><code>$request = $client-&gt;put("/api/v1/Functions/10/$_SESSION[eventID]/$functionID", array('headers' =&gt; array('token' =&gt; $token)));
  $request-&gt;setBody($data);
  $response = $request-&gt;send();
  </code></pre>
  
  <p>And I have tried using param name json instead of body.</p>
  
  <p>I have verified the JSON string in $data.</p>
  
  <p><a href="https://guzzle3.readthedocs.io/http-client/request.html" rel="nofollow noreferrer">https://guzzle3.readthedocs.io/http-client/request.html</a> shows an example where the body is 3rd arg:</p>
  
  <p><code>$request = $client-&gt;put('http://httpbin.org/put', array(), 'this is the body');</code></p>
  
  <p>So I also tried this below but same issue...</p>
  
  <pre><code>$request = $client-&gt;put("/api/v1/Functions/10/".$_SESSION['eventID'].'/'.$functionID, array(
                          'headers'   =&gt; array(
                              'token' =&gt; $token,  
                              'debug' =&gt; true,            
                          )), $data);
  </code></pre>
  
  <p>Debug output is </p>
  
  <pre><code>PUT /api/v1/Functions/10/5524/321 HTTP/1.1
  User-Agent: GuzzleHttp/6.3.3 curl/7.52.1 PHP/7.3.6-1+0~20190531112735.39+stretch~1.gbp6131b7
  Host: example.com
  token: tokenisreallyhere==
  debug: 1
  
  {"OrganizationCode":10,"EventID":"5524","FunctionID":"321","Description":"Test"}PUT /api/v1/Functions/10/5524/321 HTTP/1.1
  User-Agent: GuzzleHttp/6.3.3 curl/7.52.1 PHP/7.3.6-1+0~20190531112735.39+stretch~1.gbp6131b7
  Host: example.com
  token: tokenisreallyhere==
  debug: 1
  
  {"OrganizationCode":10,"EventID":"5524","FunctionID":"321","Description":"Test"}HTTP/1.1 400 Missing model object in request body.  Check body And header content type.
  Cache-Control: no-cache
  Pragma: no-cache
  Expires: -1
  ETag: ""
  X-Frame-Options: SAMEORIGIN
  Date: Thu, 05 Sep 2019 21:57:06 GMT
  Content-Length: 0
  </code></pre>
  
  <p>Where do I set the body?</p>