function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BIRJA KUMARBIRJA KUMAR 

How to use salesforce API in php?

Hi,
I am beginner in salesforce,
Can anyone tell, how to integrate salesforce api in php.
Deepish AdwaniDeepish Adwani

Hi Birja,

i guess you want to access the API through which all the sObjects will be accessable.
Here is the sample connection from PHP using curl:
 

function SFConnection()
  {
        $url = 'https://login.salesforce.com/services/oauth2/token';
        $fields = array(
                            'grant_type'    => 'password',
                            'client_id'     => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
                            'client_secret' => 'XXXXXXXXX',
                            'username'      => 'youremail@yourdomain.com',
                            'password'      => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
                        );

        $fields_string = http_build_query($fields);

        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL, $url);
        curl_setopt($ch,CURLOPT_POST, count($fields));
        curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

        print "\nConnecting to Salesforce\n";
        
        $result = curl_exec($ch);
        
        print "\nConnection Response from Salesforce\n";
        print  $result."\n";
        
        $obj = json_decode($result);
        
        if($obj != null)
        {
            $this->instance_url = $obj->instance_url;
            $this->access_token  = $obj->access_token; 
        }
        curl_close($ch);  
        
        $url = $this->instance_url.'/services/data/v29.0/';
        
        $ch2 = curl_init();
        curl_setopt($ch2,CURLOPT_URL, $url);
        curl_setopt($ch2,CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch2,CURLOPT_RETURNTRANSFER, true);
        $head = 'Authorization: Bearer '.$this->access_token;
        curl_setopt($ch2, CURLOPT_HTTPHEADER, array($head));

        //execute post
        $result = null;
        $result = curl_exec($ch2);

        $services = json_decode($result);
        
        $this->query_url = $this->instance_url.$services->query.'?q=';
  }
Let me know if this helps.
Vinod Kumar 472Vinod Kumar 472

Hello
where i can get below info.

 

grant_type, client_id, client_secret