Iโve been trying to create a SalesForce REST API guide for the past few days, but I canโt make it work for life. I can get the access token without problems, but from there, to create leadership, I was completely out of luck.
I see everything in all the documentation:
curl https://na1.salesforce.com/services/data/v20.0/sobjects/Account/ -H "Authorization: Bearer token -H "Content-Type: application/json" -d @newaccount.json"
How would this be done in PHP curl? I tried and tried, but I had no luck.
This is how I got the access token:
$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&client_id=".CONSUMER_KEY."&client_secret=".CONSUMER_SECRET."&username=".USERNAME."&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);
I tried to do something similar after this code, however I was out of luck.
$token_url = LOGIN_BASE_URL.'/services/oauth2/token'; $post_fields = array( 'code' => $code, 'grant_type' => 'authorization_code', 'client_id' => CONSUMER_KEY, 'client_secret' => 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)
I just need to figure out how to create leaders 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.