Error with ampersand in XML in Zoho API

2020-04-18 08:55发布

I'm using the Zoho API to insert leads into the CRM.

Everything is working fine except when one of the fields contains an ampersand, in which case the response from Zoho is this:

<?xml version="1.0" encoding="UTF-8" ?>
<response uri="/crm/private/xml/Leads/insertRecords">
  <error>
    <code>4835</code>
    <message>Unable to parse XML data</message>
  </error>
</response>

I've tried the following payloads without any success:

1/

<Leads>
    <row no="1">
        <FL val="Lead Owner">me@example.com</FL>
        <FL val="Company">Marks & Spencer</FL>
    </row>
</Leads>

2/

<Leads>
    <row no="1">
        <FL val="Lead Owner">me@example.com</FL>
        <FL val="Company">Marks &amp; Spencer</FL>
    </row>
</Leads>

3/

<Leads>
    <row no="1">
        <FL val="Lead Owner">me@example.com</FL>
        <FL val="Company">Marks &#038; Spencer</FL>
    </row>
</Leads>

4/

<Leads>
    <row no="1">
        <FL val="Lead Owner">me@example.com</FL>
        <FL val="Company"><![CDATA[Marks &amp; Spencer]]></FL>
    </row>
</Leads>

I've even tested by replacing the ampersand by %26 as advised on this Zoho forum thread but with no luck.

What is the correct format to encode ampersands for Zoho queries?

标签: xml zoho
1条回答
\"骚年 ilove
2楼-- · 2020-04-18 09:20

Finally found a solution: strings containing a special characters must be contained in CDATA sections AND those special characters need to be percent encoded.

So for the example above, this gives:

<Leads>
    <row no="1">
        <FL val="Lead Owner">me@example.com</FL>
        <FL val="Company"><![CDATA[Marks %26 Spencer]]></FL>
    </row>
</Leads>

Note that the value Marks%20%26%20Spencer is also OK for the API.

查看更多
登录 后发表回答