Campaign SOAP API: How to specify greater-than ('>') or less-than ('<') in ExecuteQuery

blair_elzinga

05-05-2017

Hi, I have a simple query where I'm trying to use greater-than or less-than in a query.  The documentation has multiple examples of this, such as:

<where>
  <condition expr="(@age > 15 or @age <= 45) and  (@city = 'Newton' or @city = 'Culver City') "/>
</where>

However, when I use a similar query, <condition expr="@id < 5000"/>

 I get the response:
      <SOAP-ENV:Fault>
         <faultcode>SOAP-ENV:Client</faultcode>
         <faultstring xsi:type="xsd:string">The XML SOAP message is invalid (service 'ExecuteQuery', method 'xtk:queryDef').</faultstring>
         <detail xsi:type="xsd:string"><![CDATA[(16:38) : A '<' character cannot be used in attribute 'expr', except through &lt;
...

So then I try as the error message suggests and use '&lt' instead of <

<condition expr="@id &lt 5000"/>

and I get a different error message:

 <faultstring xsi:type="xsd:string">The XML SOAP message is invalid (service 'ExecuteQuery', method 'xtk:queryDef').</faultstring>
         <detail xsi:type="xsd:string"><![CDATA[(16:40) : Unterminated entity reference, 'lt'
 

How can I specify '>' or '<' in my SOAP xml to get the API ExecuteQuery to work?

Accepted Solutions (1)

Accepted Solutions (1)

Vapsy

Employee

05-05-2017

Hi Blair,

Symbols '<' and '>' are restricted for use in XML. Hence they need to be used in escaped form.

Try using the following where clause and it should help.

<condition expr="@id &gt; 25"/> 

or 

<condition expr="@id &lt; 5000"/>

Regards,

Vipul

Answers (6)

Answers (6)

florentlb

10-05-2017

Hi Blair,

Did you have a chance to try Vipul's answer as well? From what you mentioned in your initial question, I saw that the ";" character was missing from your condition ("&lt" instead of "&lt;".

Let us know 🙂

Florent.

blair_elzinga

05-05-2017

The mystery deepens:

I just tried this query, and it works with '>'!?:

<queryDef schema="nms:recipient" operation="select" lineCount="100">   
    <select>     
      <node expr="@email"/>     
      <node expr="@lastName"/>     
      <node expr="@firstName"/>   
    </select>   
    <where>     
      <condition expr="@id > 25"/>   
    </where>   
  </queryDef>

blair_elzinga

05-05-2017

here is my full soap contents:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:xtk:queryDef">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:ExecuteQuery>
         <urn:sessiontoken>[deleted]</urn:sessiontoken>
         <urn:entity>
<queryDef operation="select" schema="nms:recipient" lineCount="100" >
    <select>
        <node expr="@memberKey"/>
        <node expr="@email"/>
        <node expr="@blackListEmail"/>
        <node expr="@blackList"/>
    </select>
    <where>
        <condition expr="@email like '%@%' and (@blackList = 1 or @blackListEmail = 1)"/>
        <condition expr="@id < 5000"/>
    </where>
</queryDef>
         </urn:entity>
      </urn:ExecuteQuery>
   </soapenv:Body>
</soapenv:Envelope>