title: Retrieving JSON response using HTTPful library for Laravel
body: <p>I am currently building a e-mail client (inbound and outbound sending) using Mandrill as the e-mail sending / inbound service and Laravel 3.x.</p>
  
  <p>In order to send messages, I am using the <a href="http://bundles.laravel.com/bundle/httpful" rel="nofollow">HTTPful bundle</a> with the <a href="https://mandrillapp.com/api/docs/messages.html#method=send" rel="nofollow">Mandrill</a> using the following code in my mail/compose POST method.</p>
  
  <pre><code>$url = 'https://mandrillapp.com/api/1.0/messages/send.json';
  $data = array( 
    'key' =&gt; '{removedAPIkey}',
    'message' =&gt; array (
      'to'    =&gt;  array( array( "email" =&gt; $_to ) ),
      'from_name'   =&gt;  Auth::user()-&gt;name,
      'from_email'  =&gt;  Auth::user()-&gt;email,
      'subject' =&gt;  $_subject,
      'html'    =&gt;  $_body
      ),
    'async' =&gt; true
          );
  
  $request = Httpful::post($url)-&gt;sendsJson()-&gt;body($data)-&gt;send();
  </code></pre>
  
  <p>Link to better formatted code above: <a href="http://paste.laravel.com/m79" rel="nofollow">http://paste.laravel.com/m79</a></p>
  
  <p>Now as far as I can tell from the API log, the request is correctly made (with the expected JSON) and a response of the following format is sent back:</p>
  
  <pre><code>[
    {
        "email": "test@test.com",
        "status": "queued",
        "_id": "longmessageID"
    }
  ]
  </code></pre>
  
  <p>However, what I am trying to do is access the response from the request (specifically the _id attribute), which is in JSON. Now as far as I'm aware, the HTTPful class should do this automatically (using json_decode()). However, accessing:</p>
  
  <pre><code>$request-&gt;_id;
  </code></pre>
  
  <p>is not working and I'm not entirely sure how to get this data out (it is required so I can record this for soft-bounce, hard-bounce and rejection messages for postmaster-like functionality)</p>
  
  <p>Any assistance would be appreciated.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Using the following code, results in the mail being sent but an error returned:</p>
  
  <pre><code>$url = 'https://mandrillapp.com/api/1.0/messages/send.json';
  $data = array( 
    'key' =&gt; '{removedAPIkey}',
    'message' =&gt; array (
      'to'    =&gt;  array( array( "email" =&gt; $_to ) ),
      'from_name'   =&gt;  Auth::user()-&gt;name,
      'from_email'  =&gt;  Auth::user()-&gt;email,
      'subject' =&gt;  $_subject,
      'html'    =&gt;  $_body
      ),
    'async' =&gt; true
          );
  
  $request = Httpful::post($url)-&gt;sendsJson()-&gt;body($data)-&gt;send();
  
  if ( $request[0]-&gt;status == "queued" ) {
      $success = true;
  }
  </code></pre>
  
  <p>Results in an exception being thrown: <code>Cannot use object of type Httpful\Response as array</code></p>