[SalesForce] Salesforce PHP API : INVALID_LOGIN

I am working with Salesforce PHP API(https://developer.salesforce.com/page/PHP_Toolkit_20.0_Samples) to retreive and update information. But do get the INVALID_LOGIN error when trying to execute if from server.I am trying to correct to our development instance.
I double checked the username and password and they are correct. I tried it using SoapUI and it is working fine. As per the API, I need to change the URL on wsdl to "https://test.salesforce.com/services/Soap/u/27.0".

I am using the partner method to retrieve information.

Below is the request and response back from server(I have changed the username/pasword through)

    [sforce:protected] => SforceSoapClient Object
        (           
            [trace] => 1
            [compression] => 32
            [_encoding] => utf-8
            [_features] => 1    
            [_user_agent] => salesforce-toolkit-php/27.0
            [_soap_version] => 1    
            [sdl] => Resource id #11
            [__last_request] => <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:partner.soap.sforce.com"><SOAP-ENV:Body><ns1:login><ns1:username>abc@xyz.com.dev</ns1:username><ns1:password>test1ua1</ns1:password></ns1:login></SOAP-ENV:Body></SOAP-ENV:Envelope>

            [httpsocket] => Resource id #12 
            [_use_proxy] => 0               
            [httpurl] => Resource id #13        
            [__last_request_headers] => POST /services/Soap/u/27.0 HTTP/1.1^M
Host: login.salesforce.com^M                            
Connection: Keep-Alive^M                                    
User-Agent: salesforce-toolkit-php/27.0^M                   
Accept-Encoding: gzip, deflate^M                        
Content-Type: text/xml; charset=utf-8^M
SOAPAction: ""^M                                
Content-Length: 336^M
^M                                      

            [__last_response_headers] => HTTP/1.1 500 Server Error^M
Date: Thu, 28 Jan 2016 22:25:23 GMT^M
Set-Cookie: BrowserId=U3v2RiwfRSaGE-8qUOVSQw;Path=/;Domain=.salesforce.com;Expires=Mon, 28-Mar-2016 22:25:23 GMT^M
Expires: Thu, 01 Jan 1970 00:00:00 GMT^M
Content-Type: text/xml;charset=UTF-8^M
Transfer-Encoding: chunked^M        

            [_cookies] => Array     
                (                   
                    [BrowserId] => Array
                        (               
                            [0] => U3v2RiwfRSaGE-8qUOVSQw
                            [1] => /services/Soap/u
                            [2] => login.salesforce.com
                        )                           

                )

            [__last_response] => <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode>INVALID_LOGIN</faultcode><faultstring>INVALID_LOGIN: Invalid username, password, security token; or user locked out.</faultstring><detail><sf:LoginFault xsi:type="sf:LoginFault"><sf:exceptionCode>INVALID_LOGIN</sf:exceptionCode><sf:exceptionMessage>Invalid username, password, security token; or user locked out.</sf:exceptionMessage></sf:LoginFault></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
            [__soap_fault] => SoapFault Object
                (
                    [message:protected] => INVALID_LOGIN: Invalid username, password, security token; or user locked out.
                    [string:Exception:private] =>
                    [code:protected] => 0

On the return details above, I do see cookie browserid values as "login.salesforce.com". I crosschecked the wsdl and they point to test instance.

Any help is appreciated.

Best Answer

Below is the code that I used to connect using PHP

<?php
        /*****************************************************************
        * This code utilizes the SFDC-PHP API Code
        *****************************************************************/

        ini_set('soap.wsdl_cache_enable', '0');

        session_destroy();
        require_once ('soapclient/SforcePartnerClient.php');
        require_once ('soapclient/SforceHeaderOptions.php');



        # SALESFORCE AUTHENTICATION DETAILS

        define("USERNAME"       , "email@company.com.dev");
        define("PASSWORD"       , "account_password");
        define("SECURITY_TOKEN" , "security token");



        try {

            $mySforceConnection = new SforcePartnerClient();
            $mySoapClient = $mySforceConnection->createConnection("soapclient/partner.wsdl.xml"); // Path to the partner WSDL 
            $mylogin = $mySforceConnection->login(USERNAME, PASSWORD);

        }
        catch (Exception $e) {
            echo "Exception ".$e->faultstring."<br/><br/>";
            echo "<br/><br/>";
            echo "Last Request:<br/><br/>";
            echo $mySforceConnection->getLastRequestHeaders();
            echo "<br/><br/>";
            echo $mySforceConnection->getLastRequest();
            echo "<br/><br/>";
            echo "Last Response:<br/><br/>";
            echo $mySforceConnection->getLastResponseHeaders();
            echo "<br/><br/>";
            echo $mySforceConnection->getLastResponse();
        }


?>

I tried using including the security code as part of password. But didn't work.

Related Topic