Struggling with SOAP number lookup

Status
Not open for further replies.

podtris

Customer
Joined
Jan 17, 2022
Messages
9
Reaction score
1
Hello all

I've got so far with this but have got stuck!

Basically I can connect to the SOAP service for SAP ByD and get the right data returned in the XML, but the XPath I'm using doesn't seem to be working, or I've configured something wrong so outputs aren't returned.

The official error message when I test it is: CRM Integration is working OK but contact number does not exist. Check log for more info or try a different number.

The output from the test is (note I've replaced sensitive data with removed):
Started scenario with empty id
Request text: https://removed.sapbydesign.com/sap/bc/srt/scs/sap/businesspartnerdatamanagement1
Request message: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:glob="http://sap.com/xi/SAPGlobal20/Global">
<soapenv:Header/>
<soapenv:Body>
<n0:CallingBusinessPartnerByPhoneNumberQuery_sync xmlns:n0="http://sap.com/xi/SAPGlobal20/Global">
<CallingBusinessPartnerSelectionByPhoneNumber>
<NormalisedNumberDescription>+44123456789</NormalisedNumberDescription>
</CallingBusinessPartnerSelectionByPhoneNumber>
</n0:CallingBusinessPartnerByPhoneNumberQuery_sync>
</soapenv:Body>
</soapenv:Envelope>
Response text: <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"><soap-env:Header/><soap-env:Body><n0:CallingBusinessPartnerByPhoneNumberResponse_sync xmlns:n0="http://sap.com/xi/SAPGlobal20/Global" xmlns:prx="urn:sap.com:proxy:H9L:/1SAI/TAS5E8D7998593639256065:804"><CallingBusinessPartner><UUID>00163ebe-f917-1edb-baa8-497f0a413e47</UUID><InternalID>8000000012</InternalID><CategoryCode>1</CategoryCode><LifeCycleStatusCode>2</LifeCycleStatusCode><CurrentBusinessCharacters><EmployeeIndicator>true</EmployeeIndicator></CurrentBusinessCharacters><Common><BusinessPartnerFormattedName>Removed Removed</BusinessPartnerFormattedName><Person><GivenName>Removed</GivenName><FamilyName>REmoved</FamilyName></Person></Common><UniformAddress><DefaultMobilePhone><Number><SubscriberID>123456789</SubscriberID><CountryCode>GB</CountryCode><CountryDiallingCode>+44</CountryDiallingCode></Number><FormattedNumberDescription>+44 123456789</FormattedNumberDescription><NormalisedNumberDescription>+44123456789</NormalisedNumberDescription><ValidityPeriod><StartDate>0000-00-00</StartDate><EndDate>0000-00-00</EndDate></ValidityPeriod><MobilePhoneNumberIndicator>true</MobilePhoneNumberIndicator><SMSEnabledIndicator>true</SMSEnabledIndicator></DefaultMobilePhone><AddressHostTypeCode>4</AddressHostTypeCode><DefaultEMail><URI>[email protected]</URI></DefaultEMail></UniformAddress></CallingBusinessPartner></n0:CallingBusinessPartnerByPhoneNumberResponse_sync></soap-env:Body></soap-env:Envelope>
Response finished
Finished scenario with empty id

My XML config file is attached (again with sensitive info removed)

For the variable paths, I've tried both:
/*[local-name() = 'Envelope']/*[local-name() = 'Body']/*[local-name() = 'CallingBusinessPartnerByPhoneNumberResponse_sync']/CallingBusinessPartner[1]/Common/BusinessPartnerFormattedName/text()

and:
String(/*[local-name() = 'Envelope']/*[local-name() = 'Body']/*[local-name() = 'CallingBusinessPartnerByPhoneNumberResponse_sync']/CallingBusinessPartner[1]/Common/BusinessPartnerFormattedName/text())

This article seems to suggest one of the above should work: https://www.3cx.com/community/threads/help-with-xml-parser.70651/

Would be really of any ideas or help on this please!

Many thanks
Podtris
 

Attachments

Can you check if they have a REST endpoint? SOAP is an old technology, and the XML parsing sometimes has issues with the namespaces.... It will be much simpler if you can connect through REST...
 
  • Like
Reactions: Evolute IT
Hello Ernesto

Yes I certainly agree! I looked into this before I started work on SOAP, unfortunately there isn't. So if you have any ideas I would be glad to hear them!

Thanks very much for your reply, appreciate any support you can give.
 
Hello Ernesto

Yes I certainly agree! I looked into this before I started work on SOAP, unfortunately there isn't. So if you have any ideas I would be glad to hear them!

Thanks very much for your reply, appreciate any support you can give.
How about a proxy? Use a PHP script as the REST API and have that script do the SOAP. PHP has an extension for SOAP and can also use the descriptors (schema) to ease the manipulation of data.
 
  • Like
Reactions: edossantos
How about a proxy? Use a PHP script as the REST API and have that script do the SOAP. PHP has an extension for SOAP and can also use the descriptors (schema) to ease the manipulation of data.
Thanks ConceptsWeb, I thought about that as well but I've got so far down the road that I thought I'd be able to get this last bit sorted!

Does all my other work look correct then, is it just the XPath and assigning of the values to variables that isn't working do you think? Just so I know it's not because I've missed anything obvious?
 
Last edited:
Any further comments on this please @edossantos ?

Does all my other work look correct, is it just the XPath and assigning of the values to variables that isn't working do you think? Just so I know it's not because I've missed anything obvious?

Many thanks!
Tristan
 
Hello @podtris,

I didn't test this with the CRM tool, because I don't have a web service that provides this XML response. But I tested the XPath expression with this online tool, entering the following XML:
XML:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:Header/>
    <soap-env:Body>
        <n0:CallingBusinessPartnerByPhoneNumberResponse_sync xmlns:n0="http://sap.com/xi/SAPGlobal20/Global" xmlns:prx="urn:sap.com:proxy:H9L:/1SAI/TAS5E8D7998593639256065:804">
            <CallingBusinessPartner>
                <UUID>00163ebe-f917-1edb-baa8-497f0a413e47</UUID>
                <InternalID>8000000012</InternalID>
                <CategoryCode>1</CategoryCode>
                <LifeCycleStatusCode>2</LifeCycleStatusCode>
                <CurrentBusinessCharacters>
                    <EmployeeIndicator>true</EmployeeIndicator>
                </CurrentBusinessCharacters>
                <Common>
                    <BusinessPartnerFormattedName>Removed Removed</BusinessPartnerFormattedName>
                    <Person>
                        <GivenName>Removed</GivenName>
                        <FamilyName>REmoved</FamilyName>
                    </Person>
                </Common>
                <UniformAddress>
                    <DefaultMobilePhone>
                        <Number>
                            <SubscriberID>123456789</SubscriberID>
                            <CountryCode>GB</CountryCode>
                            <CountryDiallingCode>+44</CountryDiallingCode>
                        </Number>
                        <FormattedNumberDescription>+44 123456789</FormattedNumberDescription>
                        <NormalisedNumberDescription>+44123456789</NormalisedNumberDescription>
                        <ValidityPeriod>
                            <StartDate>0000-00-00</StartDate>
                            <EndDate>0000-00-00</EndDate>
                        </ValidityPeriod>
                        <MobilePhoneNumberIndicator>true</MobilePhoneNumberIndicator>
                        <SMSEnabledIndicator>true</SMSEnabledIndicator>
                    </DefaultMobilePhone>
                    <AddressHostTypeCode>4</AddressHostTypeCode>
                    <DefaultEMail>
                        <URI>[email protected]</URI>
                    </DefaultEMail>
                </UniformAddress>
            </CallingBusinessPartner>
        </n0:CallingBusinessPartnerByPhoneNumberResponse_sync>
    </soap-env:Body>
</soap-env:Envelope>

And the following XPath expression:
string(/soap-env:Envelope/soap-env:Body/n0:CallingBusinessPartnerByPhoneNumberResponse_sync/CallingBusinessPartner/Common/BusinessPartnerFormattedName)

And I see the correct node value being returned:
1642684201304.png

So please try with that XPath expression.
 
  • Like
Reactions: Evolute IT
Thanks very much for that @edossantos

However unfortunately whilst that works in the XPath checker, it doesn't seem to work for the CRM integration - I'm still getting the same messages
"CRM Integration is working OK but contact number does not exist. Check log for more info or try a different number." and "Finished scenario with empty id"

Do you have any other ideas please? And are we sure I've created the rest of the CRM integration correctly please?

thanks a lot, much appreciated!
 
Hello @podtris,

I got confused because we don't use XML responses very often, all the integrations we do use JSON....

But the thing is that you can't use XPath expressions here. The XML is parsed to a structure in memory, which is the same representation for JSON or XML. So the Path expression you need to use should be element names separated by dots. For example, I managed to get the values from the sample XML you're getting using the following testing template:
XML:
<?xml version="1.0"?>
<Crm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="New Template" Version="0" SupportsEmojis="false">
  <Number Prefix="AsIs" MaxLength="" />
  <Connection MaxConcurrentRequests="2" />
  <Parameters />
  <Authentication Type="No" />
  <Scenarios>
    <Scenario Type="REST">
      <Request Url="http://localhost/Response.xml" MessagePasses="0" RequestEncoding="UrlEncoded" RequestType="Get" ResponseType="Xml" />
      <Rules>
        <Rule Type="Any" Ethalon="">Body.CallingBusinessPartnerByPhoneNumberResponse_sync.CallingBusinessPartner.UUID</Rule>
      </Rules>
      <Variables>
        <Variable Name="InternalID">Body.CallingBusinessPartnerByPhoneNumberResponse_sync.CallingBusinessPartner.InternalID</Variable>
        <Variable Name="GivenName">Body.CallingBusinessPartnerByPhoneNumberResponse_sync.CallingBusinessPartner.Common.Person.GivenName<Filter /></Variable>
        <Variable Name="FamilyName">Body.CallingBusinessPartnerByPhoneNumberResponse_sync.CallingBusinessPartner.Common.Person.FamilyName<Filter /></Variable>
        <Variable Name="NormalisedNumberDescription">Body.CallingBusinessPartnerByPhoneNumberResponse_sync.CallingBusinessPartner.UniformAddress.DefaultMobilePhone.NormalisedNumberDescription<Filter /></Variable>
      </Variables>
      <Outputs AllowEmpty="false">
        <Output Type="FirstName" Passes="0" Value="[GivenName]" />
        <Output Type="LastName" Passes="0" Value="[FamilyName]" />
        <Output Type="PhoneBusiness" Passes="0" Value="[NormalisedNumberDescription]" />
        <Output Type="ContactUrl" Passes="0" Value="https://someprefix/[InternalID]" />
      </Outputs>
    </Scenario>
  </Scenarios>
</Crm>

Please give it a try.
 
  • Like
Reactions: Evolute IT
Superb, thanks so much @edossantos - this is working now! I just had to add the country in and make a few other tweaks.

For anyone who is looking to integrate SAP Business By Design (ByD) with 3CX, here is the finished config file (with domain and authentication details removed):

XML:
<?xml version="1.0"?>
<Crm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="SAP ByD" Country="GB" Version="0" SupportsEmojis="false">
    <Number Prefix="AsIs" MaxLength="" />
    <Connection MaxConcurrentRequests="16" />
    <Parameters>
        <Parameter Name="Domain" Type="String" Editor="String" Default="[ENTER-TENANT-HERE].sapbydesign.com" />
    </Parameters>
    <Authentication Type="No" />
    <Scenarios>
        <Scenario Type="REST">
            <Request Url="https://[Domain]/sap/bc/srt/scs/sap/businesspartnerdatamanagement1" MessagePasses="0" Message="&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:glob=&quot;http://sap.com/xi/SAPGlobal20/Global&quot;&gt;&#xD;&#xA;   &lt;soapenv:Header/&gt;&#xD;&#xA;   &lt;soapenv:Body&gt;&#xD;&#xA;       &lt;n0:CallingBusinessPartnerByPhoneNumberQuery_sync xmlns:n0=&quot;http://sap.com/xi/SAPGlobal20/Global&quot;&gt;&#xD;&#xA; &lt;CallingBusinessPartnerSelectionByPhoneNumber&gt;&#xD;&#xA;  &lt;NormalisedNumberDescription&gt;[Number]&lt;/NormalisedNumberDescription&gt;&#xD;&#xA; &lt;/CallingBusinessPartnerSelectionByPhoneNumber&gt;&#xD;&#xA;&lt;/n0:CallingBusinessPartnerByPhoneNumberQuery_sync&gt;&#xD;&#xA;   &lt;/soapenv:Body&gt;&#xD;&#xA;&lt;/soapenv:Envelope&gt;" RequestContentType="text/xml" RequestEncoding="UrlEncoded" RequestType="Post" ResponseType="Xml">
                <Headers>
                    <Value Key="Authorization">Basic [ENTER-HASH-HERE]</Value>
                </Headers>
            </Request>
            <Rules>
                <Rule Type="Any">Body.CallingBusinessPartnerByPhoneNumberResponse_sync.CallingBusinessPartner.UUID</Rule>
            </Rules>
            <Variables>
                <Variable Name="InternalID">Body.CallingBusinessPartnerByPhoneNumberResponse_sync.CallingBusinessPartner.InternalID</Variable>
                <Variable Name="CompanyName">Body.CallingBusinessPartnerByPhoneNumberResponse_sync.CallingBusinessPartner.Common.BusinessPartnerFormattedName</Variable>
                <Variable Name="PhoneBusiness">Body.CallingBusinessPartnerByPhoneNumberResponse_sync.CallingBusinessPartner.UniformAddress.DefaultTelephone.NormalisedNumberDescription</Variable>
                <Variable Name="PhoneMobile">Body.CallingBusinessPartnerByPhoneNumberResponse_sync.CallingBusinessPartner.UniformAddress.DefaultMobilePhone.NormalisedNumberDescription</Variable>
            </Variables>
            <Outputs AllowEmpty="false">
                <Output Type="CompanyName" Passes="0" Value="[IIf([[InternalID].Substring(0, 3)]==&quot;000&quot;,[[InternalID].Substring(3, 7)],[InternalID])] | [CompanyName]" />
                <Output Type="PhoneBusiness" Passes="0" Value="[PhoneBusiness]" />
                <Output Type="PhoneMobile" Passes="0" Value="[PhoneMobile]" />
                <Output Type="ContactUrl" Passes="0" Value="[InternalID]" />
            </Outputs>
        </Scenario>
    </Scenarios>
</Crm>

Thanks again for everyone's help with this, much appreciated.
 
  • Like
Reactions: edossantos
We tried to integrate SAP but they were not cooperative lol
 
Status
Not open for further replies.

Latest Posts

Forum statistics

Threads
112,323
Messages
591,896
Members
165,473
Latest member
NathanMitchell