NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Salesforce.com API


Joined: 08 Mar 2004
Posts: 3
Reply with quote
Hi,

I am having problems logging onto the salesforce.com API. I have got the partner.wsdl file and that seems to load OK, however the username and password being passed to the login function seems to be the first letter of the username, e.g. if u is 'abcd' and p is 'efgh', the values passed are 'a' and 'a'.

I have tried with and without the getProxy() function.

Anyone got any ideas, or used the salesforce API?

$this->soapclient = new soapclient('partner.wsdl','wsdl');

$params = array("username" => "abc","password" => "def");

if($this->debug)
print"login($username,$password) called.<br>";

$result = $this->soapclient->call("login",$params);

if($err = $this->soapclient->getError())
{
print"Error : <br>$err <br>";
return;
}

return $result;
View user's profileFind all posts by katrien_ieSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 7857
Reply with quote
why don't you do like this ?

Code:
$this->soapclient = new soapclient('partner.wsdl','wsdl');
$proxy = $this->soapclient->getProxy();
$result = $proxy->login($username, $password);
if($err = $proxy->getError()) {
  print"Error : <br>$err <br>";
  return;
}

return $result;


if you still have a trouble, you may debug this code and inspect if proper packet is sent to the soap server.
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 08 Mar 2004
Posts: 3
Reply with quote
ddmitrie wrote:
why don't you do like this ?

Code:
$this->soapclient = new soapclient('partner.wsdl','wsdl');
$proxy = $this->soapclient->getProxy();
$result = $proxy->login($username, $password);
if($err = $proxy->getError()) {
  print"Error : <br>$err <br>";
  return;
}

return $result;


if you still have a trouble, you may debug this code and inspect if proper packet is sent to the soap server.


Thanks but ...

I tried that already with the same results. The proper packet is not being sent.
assuming username = 'username'
password = 'password'

The username and password tags are like this:

<username>u</username>
<password>u</password>

That's why I got rid of the getProxy call, but to no avail.
View user's profileFind all posts by katrien_ieSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 7857
Reply with quote
Code below should work fine being used with nusoap v. 1.69:
Code:
<?php
require_once('nusoap.php');
$wsdl = "file://D:/path/to/salesforce.wsdl";
$soap = new soapclient($wsdl,"wsdl");
$parameters = array("username"=>"username@some.com", "password"=>"123456");
$result = $soap->call('login', array("parameters"=>$parameters));
?>
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Code works fine, but ...


Joined: 08 Mar 2004
Posts: 3
Reply with quote
The code above works fine, but the geniuses at salesforce have decided that after you login the endpoint URL changes to the value returned from the login and you have to set a session.

However it appears that nusoap reads the wsdl each time even when I changed the endpoint it reverts to the original endpoint.

I only have code from the manual in Java and .NET so feeling around in the dark a bit here.

PHP code:
Code:
   
   $result = $this->proxy->login(array('username'=>$username,'password'=>$password));
      
   

   if($this->debug)
      $this->printReqRespOutput();

   if($err = $this->proxy->getError())
   {
      print"Error : <br>$err <br>";
      return;
   }
   else   //change the endpoint
   {
      $this->sessionID    = $result["sessionId"];               //Session ID
      $this->serverURL    = $result["serverUrl"];               //Server URL
      $this->userID       = $result["userId"];                  //User ID


      print"Endpoint before: ".$this->proxy->endpoint."<br>";
      //change the endpoint (hope this works)   
      $this->proxy->endpoint = $this->serverURL;
   
      print"Endpoint after: ".$this->proxy->endpoint."<br>";
      
      //set the header
      $this->proxy->outgoing_headers["SessionHeader"] = $this->sessionID;


Output when I try to call the getTimestamp() function:

Code:
<p><b>Timestamp:</b><br>array(3) {
  ["faultcode"]=>
  string(14) "soapenv:Server"
  ["faultstring"]=>
  string(87) "Destination URL not reset. The URL returned from login must be set in the SforceService"
  ["detail"]=>
  array(1) {
    ["fault"]=>
    array(2) {
      ["exceptionCode"]=>
      string(17) "UNKNOWN_EXCEPTION"
      ["exceptionMessage"]=>
      string(87) "Destination URL not reset. The URL returned from login must be set in the SforceService"
    }
  }
}


Java code from the manual:

Code:

// Prompt the user to provide salesforce.com login credentials.
un = getUserInput("Enter user name: ");
if (un == null) {
return false;
}
pw = getUserInput("Enter password: ");
if (pw == null) {
return false;
}
System.out.println("Creating the binding to the web service...");
try {
binding = (SoapBindingStub)
new SforceServiceLocator().getSoap(new URL(loginURL));
}
catch (MalformedURLException ex4) {
}
catch (ServiceException jre) {
if (jre.getLinkedCause() != null) {
jre.getLinkedCause().printStackTrace();
}
System.out.println("ERROR: creating binding to soap service, error was: \n"
+ jre.getMessage());
System.out.println("Press the RETURN key to continue...");
return false;
}
// Time out after a minute
binding.setTimeout(60000);
    // Attempt to log in to the sforce single sign-on server
    // by invoking the login call.
    try {
      System.out.println("LOGGING IN NOW....");
      loginResult = binding.login(un, pw);
    }
catch (RemoteException ex) {
if (ex.getMessage().equals("user not valid")){
System.out.println("Please make sure that you have a valid user id and
password. \nYou can get a user name and password by signing up at \nhttps://

getUserInput();
}
System.out.println("\nFailed to successfully login, error message was: \n" +
ex.getMessage());
System.out.println("\nPress the RETURN key to continue...");
String wex = getUserInput();
if (wex.equals("v")) { System.out.println("New url: ");
loginURL = getUserInput(); }
return false;
}

// Display the returned session ID and URL to the sforce API server
System.out.println("The session id is: " + loginResult.getSessionId());
System.out.println("The new server url is: " + loginResult.getServerUrl());
      // Change the binding to the new sforce API server endpoint.
      // Required before invoking subsequent sforce API calls.
      // If the url is null, do not reset.
      if (loginResult.getServerUrl() != null) {
      try {
        binding = (SoapBindingStub)
            new SforceServiceLocator().getSoap(new java.net.
            URL(loginResult.getServerUrl()));
      }
catch (MalformedURLException ex1) {
System.out.print("\nFailed to reset the service endpoint, error message
was: \n" + ex1.getMessage());
System.out.print("\nPress the RETURN key to continue...");
getUserInput();
}
catch (javax.xml.rpc.ServiceException jre) {
if (jre.getLinkedCause() != null) {
jre.getLinkedCause().printStackTrace();
}
System.out.print("\nFailed to re System.out.print(et the service endpoint,
error message was: \n" + jre.getMessage());
System.out.print("\nPress the RETURN key to continue...");
getUserInput();
}
}
    // Instantiate a session header for this server session
    // and set the returned session ID into the session header.
    // Required for session validation in subsequent API calls.
    _SessionHeader sh = new _SessionHeader();
    sh.setSessionId(loginResult.getSessionId());
    binding.setHeader("SoapService", "SessionHeader", sh);


View user's profileFind all posts by katrien_ieSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 7857
Reply with quote
Use code to change an endpoint
Code:
$proxy->operations['login']['endpoint'] = $newlink;

or all the endpoints

Code:
foreach ($proxy->operations as $k=>$v ) {
  $proxy->operations[$v]['endpoint'] = $newlink;
}
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Salesforce.com API
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic