Sage Web Services Using PHP SOAP - php

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.

Related

php ews return more than 1,000 contacts from Exchange Server

How do I bring back all the contacts for one user from Exchange Server 2010 which throttles responses to 1000 using https://github.com/jamesiarmes/php-ews API? I tried paging but I need some example code to get it working.
I can't provide you with an example for your library (I use my own fork, Garethp/php-ews) that I suggest you check out (It's PSR-2 and PSR-4 compatible with actual updates and maintainence), but they both basically have the same approach: help you write the XML that's sent to the server. So if you want an example, you can take a look at the MSDN pages and try to replicate the XML they have as PHP Objects. Here's what you want sent over
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010" />
</soap:Header>
<soap:Body>
<m:FindItem Traversal="Shallow">
<m:ItemShape>
<t:BaseShape>AllProperties</t:BaseShape>
</m:ItemShape>
<m:IndexedPageItemView MaxEntriesReturned="3" Offset="5" BasePoint="Beginning" />
<m:SortOrder>
<t:FieldOrder Order="Ascending">
<t:FieldURI FieldURI="contacts:DisplayName" />
</t:FieldOrder>
</m:SortOrder>
<m:ParentFolderIds>
<t:DistinguishedFolderId Id="contacts" />
</m:ParentFolderIds>
</m:FindItem>
</soap:Body>
</soap:Envelope>
Note the <m:IndexedPageItemView MaxEntriesReturned="3" Offset="5" BasePoint="Beginning" />, that's how you look for the next page in a list of results
Have you tried to use different letters as initials? I thought of something like this:
$request->ContactsView->InitialName = 'A';
$request->ContactsView->FinalName = 'B';
This of would probably not work, if you have more than 1,000 contacts starting with the letter A.

Accessing a soap xml node in PHP

After breaking my head on a wall for a whole day i just think i need some help for this.
I'm receiving the following answer from a soap call :
<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:Body>
<SearchBrochuresResponse xmlns="http://services.iceportal.com/service">
<SearchBrochuresResult>
<pageNumber>0</pageNumber>
<brochures>
<SearchBrochure>
<iceID>10427</iceID>
<city>Acapulco</city>
</SearchBrochure>
</brochures>
</SearchBrochuresResult>
</SearchBrochuresResponse>
</soap:Body>
</soap:Envelope>
I tried all i could find on the subject on stackoverflow and all the other sources i found, but i couldn't access to the iceID, basically my goal is to get into a php variable the value of the iceID node.
Thanks a lot for your help.
Assume your xml data is in the variable $data you could create a simple XML object from it, then access it's nodes in the following way (example to get iceID):
$xml = simplexml_load_string($data);
$iceID = (string)$xml->children('soap', true)
->Body->children()
->SearchBrochuresResponse
->SearchBrochuresResult
->brochures
->SearchBrochure
->iceID;
You could look into XPath, the technique used to navigate and select parts of an XML document.
Wikipedia on XPath
If you need more help please post a more specific question. What have you tried? Do you only need to extract that specific value?

Get attribute from Soap Response Header in PHP

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.

sending xml file to web service using sendfile method and php

I need to send a file to a web service (ebridge) using their SendFile method. This may be too specific to their service for anyone to answer, but I thought I'd give it a try. This is the only documentation I can find regarding the SendFile method:
Purpose
This method is used to submit data for processing by ePortal.
Input parameters
Login (string) The ePortal userID.
Password (string) The ePortal password for that user.
Content (string) This is the document to be uploaded.
Filename (string) This is the name of the file with no path information.
Return Value
SendFileResult (boolean) The boolean return value represents success or failure of the submission of a document.
Here is their sample xml code for posting:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SendFile xmlns="eBridge.WebServices">
<login>mylogin</login>
<password>mypassword</password>
<content>string</content>
<filename>string</filename>
</SendFile>
</soap:Body>
</soap:Envelope>
I am also given a sample of the file (ASN.xml) that I am supposed to send. I've tried putting the xml from this file in between the content tags and just putting "test.xml" in the filename tags. That doesn't work. I know I am making a connection because if I leave it just like it is above I will get a response back, it just returns false since I didn't send anything. Perhaps I am misunderstanding what they want in content and filename? Does anyone have any ideas what I am supposed to do with this?
clarification: What I am wondering is if the xml file goes into 'content' as a string, then what is 'filename' for? Is it actually looking for a file or is this just a name that gets assigned to something later?
Ummm, are you creating a SOAPClient? That xml file is actually the body of a SOAP request and that is encapsulated by the SOAPClient class in PHP.
For the WSDL file: https://www.ebridgeservices.com/ePortalService.asmx?WSDL
Use the SOAPClient Class to build your request to their services. Use $soapReq->SendFile({args and blah here})
and if you don't like the PHP Manual: Here's an example/tutorial.
Their web page has a "live chat". Why don't you ask them?
http://www.ebridgeconnections.com/support/development-kit/API-services.html
But I believe <content> means exactly that: you're supposed to include the entire XML file - as a string - in the SOAP message.
IMHO...

PHP SoapServer and Complex Types

I am working on building a web service in PHP using the SoapServer class, but I'm running into an issue with casting of complex types.
The WSDL is completely valid, and the PHP SoapClient handles it flawlessly, but there seems to be an issue with the complex types that are returned not being cast properly. This came to light when consuming the service in .Net, as I was getting exceptions that indicated the type was not present in the given namespace.
I mangled my function numerous times, changing the namespace on the element, but .Net continues to give me errors, regardless of what namespace I use.
Consider the following abbreviation of the script:
function getCommands() {
$output = array();
// ...
foreach($result as $row) {
$output[] = new SoapVar($row, SOAP_ENC_OBJECT, 'ns1:command');
}
return $output;
}
The abbreviated response:
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="urn:MyWebService"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:getCommandsResponse>
<return SOAP-ENC:arrayType="ns1:command[12]" xsi:type="ns1:ArrayOfCommand">
<item xsi:type="ns1:command">
<!-- ... -->
</item>
<!-- ... -->
</return>
</ns1:getCommandsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
What I've noticed is that xmlns:ns1 is defined by way of the WSDL, and it does match the namespace in the WSDL. However, the .Net SOAP client doesn't seem to understand that the command element is defined there. It does, however, understand that that's where ArrayOfCommand is defined.
So my question is multipart:
Is this a known bug with the SoapServer?
If not, am I missing something grievous in my WSDL?
Am I not encoding my objects properly?
Is this an issue with .Net? If so, what's the work-around?
I was able to resolve this issue by working over the <types/> section of my WSDL again, using the Google WSDL for reference. Then, I had to work some magic in my PHP function, casting the elements of the $command appropriate to their respective types in the WSDL, and encoding the entire command as a ns2:command. When aligned with the WSDL, this all fell together nicely and .Net is having zero difficulty with it.
I'm surprised nobody in the development community was willing to answer this, but I hope someone will be able to glean from it at least some direction on how to fix their own instance of this problem.

Categories