title: Creating Leads in SalesForce using REST API in PHP
body: <p>I have been trying to create a lead from SalesForce's REST API for the past several days but I can't for the life of me get it working. I am able to get the access token no problem but from there on as far as creating a lead I am having absolutely no luck at all.</p>
  
  <p>I keep seeing in all of the documentation this:</p>
  
  <pre><code>curl https://na1.salesforce.com/services/data/v20.0/sobjects/Account/ -H "Authorization: Bearer token -H "Content-Type: application/json" -d @newaccount.json"
  </code></pre>
  
  <p>How would I do this in PHP's curl though? I have tried and tried but had no luck at all.</p>
  
  <p>Here is how I have got the access token:</p>
  
  <pre><code>$ch = curl_init();
  
  // set URL options
  
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_URL, "https://login.salesforce.com/services/oauth2/token?grant_type=password&amp;client_id=".CONSUMER_KEY."&amp;client_secret=".CONSUMER_SECRET."&amp;username=".USERNAME."&amp;password=".USERPASS.SECURITY_TOKEN);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  
  // grab HTML
  $data = curl_exec($ch);
  
  $data = json_decode($data, true);
  $code = $data['access_token'];
  
  curl_close($ch);
  </code></pre>
  
  <p>I have tried doing something like this after this code, however I have had no luck.</p>
  
  <pre><code>$token_url = LOGIN_BASE_URL.'/services/oauth2/token';
  
  $post_fields = array(
      'code' =&gt; $code,
      'grant_type' =&gt; 'authorization_code',
      'client_id' =&gt; CONSUMER_KEY,
      'client_secret' =&gt; CONSUMER_SECRET,
  );
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $token_url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  curl_setopt($ch, CURLOPT_POST, TRUE);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
  
  $token_request_body = curl_exec($ch)
  </code></pre>
  
  <p>I just need to figure out how to create leads in SalesForce, I have no idea where to go from here. Any help would be greatly appreciated as I cannot find decent documentation anywhere that helps me.</p>