Skip to content

Instantly share code, notes, and snippets.

@metadaddy
Created February 27, 2012 19:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metadaddy/1926321 to your computer and use it in GitHub Desktop.
Save metadaddy/1926321 to your computer and use it in GitHub Desktop.
How to see raw SOAP request/response in Force.com Toolkit for PHP (https://github.com/developerforce/Force.com-Toolkit-for-PHP)
<?php
require_once ('soapclient/SforcePartnerClient.php');
define("SF_SECURITY_TOKEN", getenv("SECURITY_TOKEN"));
define("SF_USERNAME", getenv("USERNAME"));
define("SF_PASSWORD", getenv("PASSWORD"));
$mySforceConnection = new SforcePartnerClient();
$mySforceConnection->createConnection("soapclient/partner.wsdl.xml");
$response = $mySforceConnection->login(SF_USERNAME, SF_PASSWORD.SF_SECURITY_TOKEN);
$query = "SELECT Id, FirstName, LastName, Phone FROM Contact LIMIT 1";
$response = $mySforceConnection->query($query);
echo "Response from query '$query'\n";
print_r($response);
echo "\n";
echo "getLastRequestHeaders()\n";
echo $mySforceConnection->getLastRequestHeaders();
echo "\n";
echo "getLastRequest()\n";
echo $mySforceConnection->getLastRequest();
echo "\n";
echo "getLastResponseHeaders()\n";
echo $mySforceConnection->getLastResponseHeaders();
echo "\n";
echo "getLastResponse()\n";
echo $mySforceConnection->getLastResponse();
echo "\n";
?>
$ php soapdebug.php
Response from query 'SELECT Id, FirstName, LastName, Phone FROM Contact LIMIT 1'
QueryResult Object
(
[queryLocator] =>
[done] => 1
[records] => Array
(
[0] => SObject Object
(
[type] => Contact
[fields] => stdClass Object
(
[FirstName] => Rose
[LastName] => Gonzalez
[Phone] => (512) 757-6000
)
[Id] => 0035000000hvfb3AAA
)
)
[size] => 1
)
getLastRequestHeaders()
POST /services/Soap/u/20.0/00D50000000IZ3Z HTTP/1.1
Host: na3-api.salesforce.com
Connection: Keep-Alive
User-Agent: salesforce-toolkit-php/20.0
Accept-Encoding: gzip, deflate
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Content-Length: 542
getLastRequest()
<?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:Header><ns1:SessionHeader><ns1:sessionId>00D50000000IZ3Z!AQ0AQGOQGeSJRZ3JVyoFTiRz26_bisFL0xJn.VedeoY62f4P2G_s0S4_uj.QpFMxvRj6cOaj4.YJKc1v1J2HT5EDi.Idyi_Z</ns1:sessionId></ns1:SessionHeader></SOAP-ENV:Header><SOAP-ENV:Body><ns1:query><ns1:queryString>SELECT Id, FirstName, LastName, Phone FROM Contact LIMIT 1</ns1:queryString></ns1:query></SOAP-ENV:Body></SOAP-ENV:Envelope>
getLastResponseHeaders()
HTTP/1.1 200 OK
Server:
Content-Encoding: gzip
Content-Type: text/xml; charset=utf-8
Content-Length: 370
Date: Mon, 27 Feb 2012 19:05:19 GMT
getLastResponse()
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sf="urn:sobject.partner.soap.sforce.com"><soapenv:Body><queryResponse><result xsi:type="QueryResult"><done>true</done><queryLocator xsi:nil="true"/><records xsi:type="sf:sObject"><sf:type>Contact</sf:type><sf:Id>0035000000hvfb3AAA</sf:Id><sf:Id>0035000000hvfb3AAA</sf:Id><sf:FirstName>Rose</sf:FirstName><sf:LastName>Gonzalez</sf:LastName><sf:Phone>(512) 757-6000</sf:Phone></records><size>1</size></result></queryResponse></soapenv:Body></soapenv:Envelope>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment