title: Paypal API, Curl not returning any output
body: <p>I'm trying to figure out the paypal API, and I have the following code, which should make a call, get an access token, and then make the API call. The first part works(up until the <code>$accesstoken</code> line), and returns the access token properly, but the second part doesn't return anything. The code this is supposed to mimic can be found here: <a href="https://developer.paypal.com/webapps/developer/docs/integration/direct/make-your-first-call/" rel="nofollow">Make Your First Call</a></p>
  
  <pre><code>$url = "https://api.sandbox.paypal.com/v1/oauth2/token";
  $headers = array(
      'Accept' =&gt; 'application/json',
      'Accept-Language' =&gt; 'en_US',
  );
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_USERPWD, $clientID . ':' . $clientSecret);
  $curl = curl_exec($ch);
  
  $x = json_decode($curl, TRUE);
  print_r($x);
  $accesstoken = $x['access_token'];
  
  
  $headers2 = array(
      'Content-Type' =&gt; 'application/json',
      'Authorization' =&gt; 'Bearer' . $accesstoken
  );
  
  $data = array(
      "intent" =&gt; "sale",
      "redirect_urls" =&gt; array(
          "return_url" =&gt; "http://example.com/your_redirect_url/",
          "cancel_url" =&gt; "http://example.com/your_cancel_url/"
      ),
      "payer" =&gt; array(
          "payment_method" =&gt; "paypal"
      ),
      "transactions" =&gt; array(
          "transactions" =&gt; array(
              "total" =&gt; ".99",
              "currency" =&gt; "USD"
          )
      )
  );
  
  $saleurl = "https://api.sandbox.paypal.com/v1/payments/payment";
  
  $sale = curl_init();
  curl_setopt($sale, CURLOPT_URL, $saleurl);
  curl_setopt($sale, CURLOPT_VERBOSE, TRUE);
  curl_setopt($sale, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($sale, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($sale, CURLOPT_SSL_VERIFYHOST, FALSE);
  curl_setopt($sale, CURLOPT_POSTFIELDS, json_encode($data));
  curl_setopt($sale, CURLOPT_HTTPHEADER, $headers2);
  $finalsale = curl_exec($sale);
  
  $verb = json_decode($finalsale, TRUE);
  print_r($verb);
  </code></pre>
  
  <p>Curl doesn't make complete sense to me, any help would be appreciated.</p>
  
  <p>UPDATE: 
  I changed the format of the headers to:</p>
  
  <pre><code>$headers2 = array(
      'Content-Type: application/json',
      'Authorization: Bearer ' . $accesstoken
  );
  </code></pre>
  
  <p>as per one of the answers. Now it is displaying:</p>
  
  <pre><code>[name] =&gt; MALFORMED_REQUEST
  [message] =&gt; Incoming JSON request does not map to API request
  [information_link] =&gt; https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST
  [debug_id] =&gt; f53a882702a04
  </code></pre>