This is the first time we are working with a platform like salesforce. We are trying to write a xml soap request with guidance of documentation we received from our client, whom is in partnership with a 3rd client that runs the software of salesforce.

The goal is to retrieve some rows of their database and print that out on the site.

According to documentation, we first need to do an login/authentication, which will return a token.

Now everytime we are trying to try to connect the code to the salesfeed link, we are getting a prefix error, that the prefix stated is not valid, however, according to the documentation, this is used in their example, so I am a bit at loss.

(I edited out the connection details)

$soap_request  = "<?xml version=\"1.0\" encoding='utf-8'?>\n";
$soap_request .= "<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>\n";
$soap_request .= "  <SOAP-ENV:Header>";
$soap_request .= "      <ntv:LoginScopeHeader xmlns:ntv='urn:partner.soap.sforce.com'> ";
$soap_request .= "          <ntv:organizationId/> ";
$soap_request .= "          <ntv:portalId/> ";
$soap_request .= "      </ntv:LoginScopeHeader>"; 
$soap_request .= "  </SOAP-ENV:Header>";
$soap_request .= "  <SOAP-ENV:Body>";
$soap_request .= "      <ntv:login xmlns:tns='urn:partner.soap.sforce.com'>";
$soap_request .= "          <ntv:username>.....</ntv:username>";
$soap_request .= "          <ntv:password>.....</ntv:password>";
$soap_request .= "      </ntv:login>";
$soap_request .= "  </SOAP-ENV:Body>";
$soap_request .= "</SOAP-ENV:Envelope>";

$header = array(
    "Content-type: text/xml;charset=\"utf-8\"",
    "Accept: text/xml",
    "Cache-Control: no-cache",
    "Pragma: no-cache",
    "SOAPAction: \"login\"",
    "Content-length: ".strlen($soap_request),

$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "https://....-api.salesforce.com/services/Soap/u/21.0" );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT,        10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST,           true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $soap_request);
curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $header);

if(curl_exec($soap_do) === false) {
    $err = 'Curl error: ' . curl_error($soap_do);
    print $err;
} else {
    $response = curl_exec($soap_do); 

This results in the following error:

not bound error for xml

I checked not only in the documentation, but also on the website, but it all is a bit unclear here.

I tried it with prefix ntv and n1.

Since I cant acces the link for the post (the api-salesforce link) I cant see what the requested prefix is.

So my question: where can I find the prefix needed for this? Is that in the backside of the salesforce? I made a dummy account to check for it but couldn't find it.

Thanks in advance

  • It's fixed now, we moved the tns decleration to the envelope and it works now, instead of calling it on the header and body. – Dorvalla Nov 28 '16 at 11:19

It looks like you are using PHP to access the Salesforce SOAP API. While it is possible to make direct calls with cURL, as you did in your example, it would be recommended to use a wrapper library instead. Your code will end up more readable and a libraries make common tasks like pagination a lot easier.

Fixing the SAXParseException

The particular issue you're asking about seems to be caused by a missing xmlns:ntv in the login element you are sending. If you change the line of code as follows, it should work:

$soap_request .= "      <ntv:login xmlns:tns='urn:partner.soap.sforce.com' " .
                 "                 xmlns:ntv='urn:partner.soap.sforce.com'>";

Using PHPForce

You could use the PHPForce library to connect to Salesforce. To connect and retrieve some database rows, your code would look like this:

$builder = new \Phpforce\SoapClient\ClientBuilder(

$client = $builder->build();

$users = $client->query('SELECT Id, SystemModstamp FROM User LIMIT 5');

foreach ($users as $user) {
    echo $user->Id . ": " . $user->SystemModstamp->format('Y-m-d H:i:') . "\n";

You can see it's much easier to work with than plain cURL. This library will handle the SOAP XML generation for you and deal with the prefixes automatically.

| improve this answer | |
  • Thanks for the feedback, however, it was an issue in documentation we received from our client, the person. The tns was moved to the envelope, and we got it fixed now. Thanks for responding and i defenatly will take your suggestion to heart, cause you are right, it starts to get unreadable :) For giving me the hint phpforce tip, i ll accept your answer ;) since we can close this now – Dorvalla Nov 28 '16 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.