PHP Curl REST API SALESFORCE Authentication using SOAPCLIENT

<div dir="ltr" style="text-align: left;" trbidi="on">
<?php
include_once('../../../../../../salesforceAPI/soapclient/SforcePartnerClient.php');
 include_once('../../../../../../salesforceAPI/soapclient/SforceHeaderOptions.php');

// Salesforce.com credentials
$username='*************';
$password='*************';
// the email address to search for. could also use a post/get variable
$searchEmail = '********';
$sfdc = new SforcePartnerClient();
// create a connection using the partner wsdl
$SoapClient = $sfdc-&gt;createConnection("../../../../../../salesforceAPI/soapclient/partner.wsdl.xml");
$loginResult = false;
try { 
    // log in with username, password and security token if required
    $loginResult = $sfdc-&gt;login($username, $password);
$access_token = $sfdc-&gt;getSessionId();
} catch (Exception $e) {
    global $errors;
    $errors = $e-&gt;faultstring;
    echo "Fatal Login Error <b>" . $errors . "</b>";
    die;
}

   $url = "https://cs57.salesforce.com/services/apexrest/apex/LeadInformation/";
     $content = json_encode(array("Email" =&gt; $email ,"Formname" =&gt; $form));
     $curl = curl_init($url);
     curl_setopt($curl, CURLOPT_HEADER, false);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_HTTPHEADER,
             array("Authorization: OAuth $access_token",
                 "Content-type: application/json"));
     curl_setopt($curl, CURLOPT_POST, true);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
     $json_response = curl_exec($curl);
    
    ?>
</div>

Share this

Related Posts

Previous
Next Post »

Pageviews from the past week