I am using php SOAP to post lead data to my client's SAGE CRM, the record get created (with crmid returned) but contains empty values. For some unknown reason my xml packet is being ignored.
The SAGE documentation does not give an xml example for adding record (addrecord) to the CRM. Can someone please help?
What is the right xml format for addrecord function?
I know this was a question back in 2013 but better have it answered in case someone else comes looking for a solution.
The following is a sample for the upload of a new opportunity into Sage CRM. I have not seen the xml you are generating but I would start by using add instead of addrecord. I have not used addrecord before so I can't help you understanding this format for uploading data.
Please note the *Specified fields as they are important. Any field to be populated which has a related *Specified field must have it set to true. Otherwise the field might not be populated.
Most of the values on the sample bellow must be replaced by actual values. The SID being the most important one.
You may enter multiple <records> within the <add> tags.
<?xml version='1.0' encoding='utf-8' ?>
<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<soap:Header>
<SessionHeader xmlns='http://tempuri.org/type'>
<sessionId>SID</sessionId>
</SessionHeader>
</soap:Header>
<soap:Body>
<add xmlns='http://tempuri.org/type'>
<entityname>opportunity</entityname>
<records xsi:type='opportunity'>
<description>description</description>
<forecast>forecast_value</forecast>
<forecastSpecified>true</forecastSpecified>
<certainty>certainty</certainty>
<certaintySpecified>true</certaintySpecified>
<targetclose>targetclose</targetclose>
<targetcloseSpecified>true</targetcloseSpecified>
<forecast_cid>forecast_cid</forecast_cid>
<forecast_cidSpecified>true</forecast_cidSpecified>
<total_cid>total_cid</total_cid>
<total_cidSpecified>true</total_cidSpecified>
<totalorders_cid>total_orders_cid</totalorders_cid>
<totalorders_cidSpecified>true</totalorders_cidSpecified>
<totalquotes_cid>totalquotes_cid</totalquotes_cid>
<totalquotes_cidSpecified>true</totalquotes_cidSpecified>
<source>source</source>
<type>type</type>
<stage>stage</stage>
<status>status</status>
<assigneduserid>assigneduserid</assigneduserid>
<assigneduseridSpecified>true</assigneduseridSpecified>
<channelid>channelid</channelid>
<channelidSpecified>true</channelidSpecified>
<priority>priority</priority>
<currency>cid</currency>
<currencySpecified>true</currencySpecified>
<primarycompanyid>primarycompanyid</primarycompanyid>
<primarycompanyidSpecified>true</primarycompanyidSpecified>
<primarypersonid>primarypersonid</primarypersonid>
<primarypersonidSpecified>true</primarypersonidSpecified>
</records>
</add>
</soap:Body>
</soap:Envelope>
You can find the web services documentation at https://community.sagecrm.com/user_community/m/cloud_documentation/27076.aspx
Download the wsdl file to get more details about each field and entity available.
I am using PHP to connect to a Web Service.
I need to connect to the web service with some login details so I can generate a Ticket to start using the methods available.
Here is some code:
//Connect To WebCrm API
$client = new SoapClient("http://b2b-email.net/apicrm1/webCRMAPI.asmx?wsdl", array('trace' => 1));
//Login
$ticket = $client->Authenticate(array('code' => 'rhgkhgk','user' =>'myusername','password' =>'apass'));
From this in the response soap header a ticket will be generated. This is generated under Ticket Header Then GUID. (See Below)
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<TicketHeader xmlns="http://www.webcrm.com/">
<Guid>TICKET->>>>>>>>e446373e-8fg0-4dfc-b876-41f3bc8990dd</Guid>
</TicketHeader>
</soap:Header>
<soap:Body>
<AuthenticateResponse xmlns="http://www.webcrm.com/">
<AuthenticateResult>
<Message />
<Code>0</Code>
</AuthenticateResult>
</AuthenticateResponse>
</soap:Body>
</soap:Envelope>
I need this ticket ID to perform any other tasks using the web service but how can access it and use it within my code?
I have tried using below:
$response = $client->__getLastResponse();
However this outputs like below:
6d5933d3-46ff-4690-893d-2af04806668c->>>>>>>>0<<<<<ZERO ON THE END
A zero is always on the end when it shouldn't be?
Any help on why this is happening on the best way i can achieve accessing the ticket from Soap Header is greatly appreciated!
As per the manual:
$soapclient->__soapCall("soapmethod", array(parameters), null, $input_headers, &$output_headers);
$output_headers should then contain the headers from the response message.
$client->__getLastResponse() returns the XML of the last response. You are viewing this in your browser, and your browser is trying to interpret this as HTML. Because of this, it will not show any XML tags and only show text. That is why the 0 is displayed. You can view the whole XML in several ways:
View the source of the PHP page
Wrap the echo statement in <xmp></xmp> tags.
Call htmlentities() on the XML before echoing it.
I am having serious issues parsing this xml array using curl. I only need the click_id printed on each new row. Does someone have an example of how I can pull this. I am using curl and get the response below in the variable $result. I am using php.
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfClick xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://cakemarketing.com/api/1/">
<Click>
<click_id>7458165</click_id>
<request_session_id>7901644</request_session_id>
<click_date>2011-09-08T13:53:37.143</click_date>
<offer_id>10346</offer_id>
<advertiser_id>1050</advertiser_id>
<campaign_id>6527</campaign_id>
</Click>
<Click>
<click_id>7459318</click_id>
<request_session_id>7903011</request_session_id>
<click_date>2011-09-08T14:41:37.953</click_date>
<offer_id>10346</offer_id>
<advertiser_id>1050</advertiser_id>
<campaign_id>6527</campaign_id>
</Click>
The best way is to use XPath with the help of this class http://php.net/manual/en/class.domxpath.php
A more simple method is to use regex (but I discourage this approach)
I am working with the XML file string below and I've tried a number of methods to try and get access to certain parts of the XML contents. Please see the code after the XML file below for my attempt:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Address_ListResponse xmlns="http://example.example.com/">
<Address_ListResult>
<Address>
<HoldingId xsi:nil="true"/>
<MainId>1617931</MainId>
<ContactId>8</ContactId>
<Description>Home, All Purposes</Description>
<Position/>
<Department/>
<Organisation/>
<AddressLabel>Mr Joe Bloggs</AddressLabel>
<AddressLine1>1 Fake Road</AddressLine1>
<AddressLine2/>
<AddressLine3/>
<Town>Faketown</Town>
<CountyId>818</CountyId>
<PostCode>FA33 4KE</PostCode>
<CountryId>3</CountryId>
<Phone>01234567890</Phone>
<EvePhone/>
<Mobile/>
<Email>joe#bloggs.com</Email>
<Fax/>
<WWW/>
<AddressTypeId>1</AddressTypeId>
<IsBilling>true</IsBilling>
<IsMailing>true</IsMailing>
<IsDelivery>true</IsDelivery>
<IsInherited>false</IsInherited>
<GridN/>
<GridE/>
<Latitude/>
<Longitude/>
<CensationCode/>
<IsDeleted>false</IsDeleted>
<HoldingPersonalDetailsId xsi:nil="true"/>
<IsSynced>false</IsSynced>
<BeenProcessed>false</BeenProcessed>
<CountyName/>
<CountryName/>
<AddressTypeName>Home</AddressTypeName>
</Address>
</Address_ListResult>
</Address_ListResponse>
</soap:Body>
</soap:Envelope>
Code for accessing the XML content:
$xml = simplexml_load_string($result);
echo "Town: " . $xml->children('http://schemas.xmlsoap.org/soap/envelope/')->children('http://example.example.com/')->Address_ListResponse->Town;
The above code was based on a link posted by another StackOverFlow question: http://blog.preinheimer.com/index.php?/archives/172-SimpleXML,-Namespaces-Hair-loss.html
Any help would be appreciated.
Thanks.
Consider using the SOAP extension instead.
See the example in the PHP Manual on how to write a client.
An alternative would be to use Zend_Soap as a standalone component.
Turns out the answer I was looking for wasn't SimpleXML - or at least I couldn't get that to work.
What I have done is used the xml_parse_into_struct to create an array of values returned from the XML data: http://www.php.net/manual/en/function.xml-parse-into-struct.php
I haven't done any xml projects, so I'm not quite sure what to do with this data...
I'm using curl to make a request to salesforce, and they give me back a response that I need to parse. I want to use simplexml. Here's part of the response:
<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">
<soapenv:Body>
<loginResponse>
<result>
<metadataServerUrl>
https://na6-api.salesforce.com/services/Soap/m/18.0/
</metadataServerUrl>
<passwordExpired>
false
</passwordExpired>
<sandbox>
false
</sandbox>
<serverUrl>
https://na6-api.salesforce.com/services/Soap/u/18.0/
</serverUrl>
<sessionId>
!AQ4AQLtDIqY.
</sessionId>
<userId>
</userId>
<userInfo>
<accessibilityMode>
false
</accessibilityMode>
<currencySymbol>
$
</currencySymbol>
<orgDefaultCurrencyIsoCode>
USD
</orgDefaultCurrencyIsoCode>
<orgDisallowHtmlAttachments>
false
</orgDisallowHtmlAttachments>
<orgHasPersonAccounts>
false
</orgHasPersonAccounts>
<organizationId>
</organizationId>
<organizationMultiCurrency>
false
</organizationMultiCurrency>
<organizationName>
Ox
</organizationName>
<profileId>
sdfgsdfg
</profileId>
<roleId>
sdfgsdfg
</roleId>
<userDefaultCurrencyIsoCode xsi:nil="true"/>
<userEmail>
####gmail.com
</userEmail>
<userFullName>
### ###
</userFullName>
<userId>
asdfasdf
</userId>
<userLanguage>
en_US
</userLanguage>
<userLocale>
en_US
</userLocale>
<userName>
asdfasdf#gmail.com
</userName>
<userTimeZone>
America/Chicago
</userTimeZone>
<userType>
Standard
</userType>
<userUiSkin>
Theme3
</userUiSkin>
</userInfo>
</result>
</loginResponse>
</soapenv:Body>
</soapenv:Envelope>
Anyway, I expected to feed that stuff (we'll call it data) into
$results = simplexml_load_string($data);
var_dump($results);
And that would give me all the data back... and then to access specific parts, it would be $results->body->loginResponse->blah->blah...
But It's not giving me that, it's not really giving me anything back, just an empty simple xml object...
So one website made me think I might need an XSLT to read this correctly.
Or something else made me think it's because I don't have at the top.
Help!
You can use SimpleXML but it's not quite as simple as you hope due to the use of namespaces (e.g. soapenv). Look into using SimpleXMLElement::children like:
$sxe = new SimpleXMLElement($data);
$login_response = $sxe->children('soapenv', TRUE)->Body->children('', TRUE)->loginResponse->result;
// Now that we have the <loginResponse> lets take a look at an item within it
echo $login_response->userInfo->userEmail;
Finally, and importantly, have you had a look at salesforce's tools & examples?
SimpleXML needs a special treatment for namespaced XML (ref.)
Mate,
Name spaces usually require you to make a call using children to return the namespaced elements. I would recommend using a soap client like php soapclient, but since I've never used it before there is one other possible option.
$results = simplexml_load_string($data);
$xml = $results->children('http://schemas.xmlsoap.org/soap/envelope/');
var_dump($xml);
I believe that's how it works.
For what it's worth, you may find you have an easier time using a PHP SoapClient for this task. O'Reilly has a good tutorial on PHP SOAP.
Also checkout the PHP Toolkit for making SOAP calls to Salesforce.com
I try to follow the syntax by salathe. But children('soapenv', TRUE) doens't work for me, Jason's children('http://schemas.xmlsoap.org/soap/envelope/') work.
Therefore, to read the field value CreatedDate in Salesforce Outbound Message, I need following code:
$rcXML->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children('http://soap.sforce.com/2005/09/outbound')->notifications->Notification->sObject->children('urn:sobject.enterprise.soap.sforce.com')->CreatedDate
To help you understand how it work, I write a post with sames code and xml which shall be easier to understand.
http://amigotechnotes.wordpress.com/2013/11/16/parse-xml-with-namespace-by-simplexml-in-php/
Parsing soap responses with SimpleXML has a brilliant and concise example of multi-namespace XML parsing.
For anyone wanting to get at the RateResponse from the UPS Rating API, here's how :
// $client is your SoapClient object
$dom = new DOMDocument;
$dom->loadXML($client->__getLastResponse());
$xml = simplexml_load_string($dom->saveXML(), NULL, NULL, 'http://schemas.xmlsoap.org/soap/envelope/');
$RateResponse = $xml->xpath('/soapenv:Envelope/soapenv:Body')[0]->children('rate', true)->RateResponse;
foreach($RateResponse->RatedShipment as $RatedShipment) {
print_r((array)$RatedShipment);
}
For SAOP request, we can parse easily with a short code by replacing the SOAP-ENV: tag with blank
$response = '<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">
<soapenv:Body>';
$response = html_entity_decode($response);
$response = str_replace(['soapenv:', 'ns1:', ':ns1', 'SOAP-ENV:'], ['', '', '', ''], $response);
$objXmlData = simplexml_load_string($response);