0

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>[email protected]</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.

7
  • "As per the API, I need to change the URL on wsdl to "test.salesforce.com/services/Soap/u/27.0"" Can you expand on this? You won't be able to login to a DE org. via test.salesforce.com, you should be using login.salesforce.com Commented Jan 28, 2016 at 23:01
  • Do you mean, even if we want to query the DEV instance of Salesforce, we should use login.salesforce.com on wsdl?
    – Gops
    Commented Jan 28, 2016 at 23:12
  • Also, the test.salesforce.com changed wsld works on SoapUI tool
    – Gops
    Commented Jan 28, 2016 at 23:13
  • I haven't used the PHP API before but normally you login to login.salesforce.com for DEV environments. Only sandboxes are logged into via test.salesforce.com Commented Jan 28, 2016 at 23:14
  • 1
    are you including the users security token with the password?
    – superfell
    Commented Jan 29, 2016 at 5:15

4 Answers 4

1

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 protected]");
        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.

0
1

If you want to connect sandbox environment follow below steps

  1. Modify your SforceBaseClient.php and point it to test.salesforce.com at line 159

enter image description here

  1. Make sure you are passing securiy token with your password if login ip range is not defined at profile level.

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

I cannot comment yet, so I am posting this as a separate answer. This code was working for me:

require_once(SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');
require_once(SOAP_CLIENT_BASEDIR.'/SforceHeaderOptions.php');

try {
    $mySforceConnection = new SforcePartnerClient();
    $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
    $mySforceConnection->setEndpoint("https://test.salesforce.com/services/Soap/u/30.0");
    $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD.$SECURITY_TOKEN);

    echo "***** Get Server Timestamp *****\n";
    $response = $mySforceConnection->getServerTimestamp();
    echo "<pre>"; print_r($response);
} catch (Exception $e) {
    echo "<pre>"; print_r($e);
}

This works without modifying SforceBaseClient.php

0

Try to generate new WSDL xml document from sandbox. Go to Senter image description hereetup -> Integrations -> API to download corresponding WSDL

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .