http://wiki.x2crm.com/index.php?title=Web_Lead_Capture_via_API_(legacy)&feed=atom&action=historyWeb Lead Capture via API (legacy) - Revision history2024-03-29T00:17:29ZRevision history for this page on the wikiMediaWiki 1.28.0http://wiki.x2crm.com/index.php?title=Web_Lead_Capture_via_API_(legacy)&diff=1799&oldid=prevDemitri at 22:54, 22 May 20142014-05-22T22:54:52Z<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;' lang='en'>
<td colspan='2' style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black; text-align: center;">Revision as of 22:54, 22 May 2014</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Development]]</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Development]]</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>This article demonstrates an example of how to build a custom <del class="diffchange diffchange-inline">API </del>script to capture and save web leads in X2Engine similar to the native web lead capture form. It is <del class="diffchange diffchange-inline">by no means generic</del>; there are many ways one can use the API to save or import contacts from third-party software systems. It is merely intended as supplemental material to the [[Remote_API|main API reference]], to which the reader should refer for more in-depth coverage of how to use the API.</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>This article demonstrates an example of how to build a custom script to capture and save web leads in X2Engine <ins class="diffchange diffchange-inline">using the legacy API, </ins>similar to the native web lead capture form. It is <ins class="diffchange diffchange-inline">not the sole way of performing this task</ins>; there are many ways one can use the API to save or import contacts from third-party software systems. It is merely intended as supplemental material to the [[Remote_API|main API reference]], to which the reader should refer for more in-depth coverage of how to use the API.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>== Introduction ==</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>== Introduction ==</div></td></tr>
</table>Demitrihttp://wiki.x2crm.com/index.php?title=Web_Lead_Capture_via_API_(legacy)&diff=1517&oldid=prevDemitri: Demitri moved page Web Lead API (new) to Web Lead Capture via API (legacy): More descriptive title2014-05-02T00:45:53Z<p>Demitri moved page <a href="/wiki/Web_Lead_API_(new)" class="mw-redirect" title="Web Lead API (new)">Web Lead API (new)</a> to <a href="/wiki/Web_Lead_Capture_via_API_(legacy)" title="Web Lead Capture via API (legacy)">Web Lead Capture via API (legacy)</a>: More descriptive title</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr style='vertical-align: top;' lang='en'>
<td colspan='1' style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan='1' style="background-color: white; color:black; text-align: center;">Revision as of 00:45, 2 May 2014</td>
</tr><tr><td colspan='2' style='text-align: center;' lang='en'><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>Demitrihttp://wiki.x2crm.com/index.php?title=Web_Lead_Capture_via_API_(legacy)&diff=1510&oldid=prevDemitri at 21:48, 21 April 20142014-04-21T21:48:40Z<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;' lang='en'>
<td colspan='2' style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black; text-align: center;">Revision as of 21:48, 21 April 2014</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l135" >Line 135:</td>
<td colspan="2" class="diff-lineno">Line 135:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>}</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>}</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div></syntaxhighlight></div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div></syntaxhighlight></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">=== Adding Tags ===</del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">=== Lead Logging ===</del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">=== Custom Redirects ===</del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">== Advanced Final Product ==</del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">With all the bells and whistles!</del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">TODO: Add this</del></div></td><td colspan="2"> </td></tr>
</table>Demitrihttp://wiki.x2crm.com/index.php?title=Web_Lead_Capture_via_API_(legacy)&diff=1509&oldid=prevDemitri at 21:47, 21 April 20142014-04-21T21:47:43Z<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;' lang='en'>
<td colspan='2' style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black; text-align: center;">Revision as of 21:47, 21 April 2014</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Development]]</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Development]]</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">This article demonstrates an example of how to build a custom API script to capture and save web leads in X2Engine similar to the native web lead capture form. It is by no means generic; there are many ways one can use the API to save or import contacts from third-party software systems. It is merely intended as supplemental material to the [[Remote_API|main API reference]], to which the reader should refer for more in-depth coverage of how to use the API.</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>== Introduction ==</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>== Introduction ==</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>'''This version the Web Lead API is only compatible with <del class="diffchange diffchange-inline">X2CRM </del>versions at or after 3.6'''</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>'''This version the Web Lead API is only compatible with <ins class="diffchange diffchange-inline">X2Engine </ins>versions at or after 3.6'''</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Much of what was written in the [[Web Lead API (legacy)|old version]] is the same, but there are some fairly key differences, namely the way our web tracker (professional feature) works. This will be addressed in its own section, but the back-end of it will be included in the capture form documentation.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Much of what was written in the [[Web Lead API (legacy)|old version]] is the same, but there are some fairly key differences, namely the way our web tracker (professional feature) works. This will be addressed in its own section, but the back-end of it will be included in the capture form documentation.</div></td></tr>
</table>Demitrihttp://wiki.x2crm.com/index.php?title=Web_Lead_Capture_via_API_(legacy)&diff=1141&oldid=prevJake: /* The Basics */2013-11-05T21:55:14Z<p><span dir="auto"><span class="autocomment">The Basics</span></span></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;' lang='en'>
<td colspan='2' style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black; text-align: center;">Revision as of 21:55, 5 November 2013</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l96" >Line 96:</td>
<td colspan="2" class="diff-lineno">Line 96:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>And that's it! For a basic web lead capture script, this is all we need. The code listed here should be totally functional to copy and paste over to your own server, as long you define your own field map, configure the APIModel constructor, and replace URLs properly. However, it's pretty basic and there's at least one extra feature that might be required to work correctly.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>And that's it! For a basic web lead capture script, this is all we need. The code listed here should be totally functional to copy and paste over to your own server, as long you define your own field map, configure the APIModel constructor, and replace URLs properly. However, it's pretty basic and there's at least one extra feature that might be required to work correctly.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>Also, you may have noticed that $_POST['x2_key'] was referenced, but it was not explained where we got that from. Please see the Web Tracker Front End section for an explanation.</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>Also, you may have noticed that $_POST['x2_key'] was referenced, but it was not explained where we got that from. Please see the <ins class="diffchange diffchange-inline">[[#</ins>Web Tracker Front End<ins class="diffchange diffchange-inline">|Web Tracker Front End]] </ins>section for an explanation.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>== Advanced Topics ==</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>== Advanced Topics ==</div></td></tr>
</table>Jakehttp://wiki.x2crm.com/index.php?title=Web_Lead_Capture_via_API_(legacy)&diff=1140&oldid=prevJake: /* Introduction */2013-11-05T21:54:27Z<p><span dir="auto"><span class="autocomment">Introduction</span></span></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;' lang='en'>
<td colspan='2' style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black; text-align: center;">Revision as of 21:54, 5 November 2013</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l3" >Line 3:</td>
<td colspan="2" class="diff-lineno">Line 3:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>'''This version the Web Lead API is only compatible with X2CRM versions at or after 3.6'''</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>'''This version the Web Lead API is only compatible with X2CRM versions at or after 3.6'''</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>Much of what was written in the old version is the same, but there are some fairly key differences, namely the way our web tracker (professional feature) works. This will be addressed in its own section, but the back-end of it will be included in the capture form documentation.</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>Much of what was written in the <ins class="diffchange diffchange-inline">[[Web Lead API (legacy)|</ins>old version<ins class="diffchange diffchange-inline">]] </ins>is the same, but there are some fairly key differences, namely the way our web tracker (professional feature) works. This will be addressed in its own section, but the back-end of it will be included in the capture form documentation.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Our web lead from editor allows for some solid forms that the average user can put on their website without much issue. Little to no development knowledge is required, and the form integrates perfectly with X2 from a web lead standpoint as well as our web tracker. But for some users, this isn't enough. Many websites already have forms in use that they don't want to sacrifice or change, but still want all of the features of X2 integration. The good news is that with some basic development knowledge this is a very doable project. This article will walk you through setting up a custom web lead capture script which will take POST data from your web lead form and enter it into X2 via API. The later sections of the article will cover some advanced customizations to make the form work better for you.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Our web lead from editor allows for some solid forms that the average user can put on their website without much issue. Little to no development knowledge is required, and the form integrates perfectly with X2 from a web lead standpoint as well as our web tracker. But for some users, this isn't enough. Many websites already have forms in use that they don't want to sacrifice or change, but still want all of the features of X2 integration. The good news is that with some basic development knowledge this is a very doable project. This article will walk you through setting up a custom web lead capture script which will take POST data from your web lead form and enter it into X2 via API. The later sections of the article will cover some advanced customizations to make the form work better for you.</div></td></tr>
</table>Jakehttp://wiki.x2crm.com/index.php?title=Web_Lead_Capture_via_API_(legacy)&diff=1139&oldid=prevJake: Created page with "Category:Development == Introduction == '''This version the Web Lead API is only compatible with X2CRM versions at or after 3.6''' Much of what was written in the old ver..."2013-11-05T21:51:45Z<p>Created page with "<a href="/wiki/Category:Development" title="Category:Development">Category:Development</a> == Introduction == '''This version the Web Lead API is only compatible with X2CRM versions at or after 3.6''' Much of what was written in the old ver..."</p>
<p><b>New page</b></p><div>[[Category:Development]]<br />
== Introduction ==<br />
'''This version the Web Lead API is only compatible with X2CRM versions at or after 3.6'''<br />
<br />
Much of what was written in the old version is the same, but there are some fairly key differences, namely the way our web tracker (professional feature) works. This will be addressed in its own section, but the back-end of it will be included in the capture form documentation.<br />
<br />
Our web lead from editor allows for some solid forms that the average user can put on their website without much issue. Little to no development knowledge is required, and the form integrates perfectly with X2 from a web lead standpoint as well as our web tracker. But for some users, this isn't enough. Many websites already have forms in use that they don't want to sacrifice or change, but still want all of the features of X2 integration. The good news is that with some basic development knowledge this is a very doable project. This article will walk you through setting up a custom web lead capture script which will take POST data from your web lead form and enter it into X2 via API. The later sections of the article will cover some advanced customizations to make the form work better for you.<br />
<br />
== The Basics ==<br />
The first thing you'll need to do is create some form of capture script, and call it whatever you like. I tend to use things like "contactForm" to be very clear what it is. '''This script can go anywhere you want as the new web tracker is much more flexible than the old version.''' You'll also need to make sure that the "APIModel.php" class file is somewhere accessible. This file is provided in protected/models/ of your X2 installation, and can be copied to anywhere you like. So, what does this capture script currently look like?<br />
<br />
<syntaxhighlight lang="php"><br />
<?php<br />
require 'APIModel.php';<br />
$attributes = $_POST;<br />
</syntaxhighlight><br />
<br />
That's about it for now. The first thing we do is include the APIModel class, which will allow for easy use of X2's API. This class is heavily documented and provides a variety of wrapper methods for common X2 API functions. It also behaves in many ways just like a regular model, so if you have any X2 development experience you'll likely feel right at home. <br />
<br />
The next steps in this process are to initialize the API Model correctly. To do that, you'll need three things:<br />
* The username of a user with permission to create Contacts<br />
* The user API key of that same user<br />
* The URL of your X2 installation.<br />
<br />
The first is easy to obtain, and I recommend using "admin" as it's simpler. From there, go to the "Users" page, click on "admin" in the grid, and select "Update User" from the left sidebar menu. You should see a field called API Key. You can set this to whatever you want, but they're randomly generated upon user creation. For example, mine on my development server at the time of this writing is "7uoHGRIBlb0lKym56ieiDf3c7idzCCP7"<br />
<br />
The API Model takes 3 parameters for its constructor. You may be able to guess that they are the username, API key, and URL of the server. So now our code should look something like this:<br />
<br />
<syntaxhighlight lang="php"><br />
$contact = new APIModel('admin','7uoHGRIBlb0lKym56ieiDf3c7idzCCP7','www.host.domain/path/to/x2');<br />
</syntaxhighlight><br />
<br />
That's the most important step to get right. If you don't properly set up your API model, all of the requests will fail and this whole process will be useless. '''Please double check you have entered in the information correctly.'''<br />
<br />
Now we need to be able to set the data of our Contact. Most pre-built forms do not follow the same naming conventions of the database columns in X2. As such, I like to build a field map that will translate the information in the POST data into usable information by X2. If all your field names match ours exactly, then this step isn't required and you can simply say <tt>$contact->attributes = $attributes;</tt><br />
<br />
<syntaxhighlight lang="php"><br />
$fieldMap = array( // This map should be of the format 'your_fieldname'=>'x2_fieldname',<br />
'first_name'=>'firstName',<br />
'last_name'=>'lastName',<br />
'mobile'=>'phone2',<br />
'information'=>'backgroundInfo',<br />
);<br />
foreach($attributes as $key=>$value){<br />
if(isset($fieldMap[$key])){<br />
$contact->{$fieldMap[$key]}=$value; // Found in field map, used mapped attribute<br />
}else{<br />
$contact->$key=$value; // No match anywhere, assume it's a Contact attribute<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
This code will now loop through your POST data and set them to the Contact attributes based on your field map. Note that if a match isn't found in the map, it assumes the names are the same in your form as they are in X2.<br />
<br />
You'll also want to include the tracking key, if it exists. This is now provided up front instead of returned after creation, so this code should just be a few extra lines before you submit the data to the API.<br />
<syntaxhighlight lang="php"><br />
if(isset($_POST['x2_key'])){<br />
$contact->trackingKey=$_POST['x2_key'];<br />
}<br />
</syntaxhighlight><br />
<br />
The last component of the custom form is submitting the data and redirecting. You can do these like so:<br />
<br />
<syntaxhighlight lang="php"><br />
$contact->contactCreate(); // Call API to create contact<br />
Header('Location: host.domain/redirect'); // Redirect to homepage<br />
</syntaxhighlight><br />
<br />
And be sure to replace '/path/to/x2' with your web path, 'host.domain' with your server URL, and the redirect with whatever URL you want visitors to be sent to after filling out the form. Now, if we put it all together, the final product should look something like this:<br />
<br />
<syntaxhighlight lang="php"><br />
<?php<br />
require 'APIModel.php';<br />
$attributes = $_POST;<br />
$contact = new APIModel('admin','7uoHGRIBlb0lKym56ieiDf3c7idzCCP7','www.host.domain/path/to/x2');<br />
$fieldMap = array( // This map should be of the format 'your_fieldname'=>'x2_fieldname',<br />
'first_name'=>'firstName',<br />
'last_name'=>'lastName',<br />
'mobile'=>'phone2',<br />
'information'=>'backgroundInfo',<br />
);<br />
foreach($attributes as $key=>$value){<br />
if(isset($fieldMap[$key])){<br />
$contact->{$fieldMap[$key]}=$value; // Found in field map, used mapped attribute<br />
}else{<br />
$contact->$key=$value; // No match anywhere, assume it's a Contact attribute<br />
}<br />
}<br />
if(isset($_POST['x2_key'])){<br />
$contact->trackingKey=$_POST['x2_key'];<br />
}<br />
$contact->contactCreate(); // Call API to create contact<br />
Header('Location: host.domain/redirect'); // Redirect to homepage<br />
</syntaxhighlight><br />
<br />
And that's it! For a basic web lead capture script, this is all we need. The code listed here should be totally functional to copy and paste over to your own server, as long you define your own field map, configure the APIModel constructor, and replace URLs properly. However, it's pretty basic and there's at least one extra feature that might be required to work correctly.<br />
<br />
Also, you may have noticed that $_POST['x2_key'] was referenced, but it was not explained where we got that from. Please see the Web Tracker Front End section for an explanation.<br />
<br />
== Advanced Topics ==<br />
TODO: Add this section<br />
=== Web Tracker Front End===<br />
The new web tracker is significantly more reliable and flexible to work with. However, you'll need to make a slight change to your HTML form to make it work. What you'll want to do is create a hidden input in your form with the name "x2_key" and that's it! Our web tracker JS will automatically detect this field and fill it with the correct tracking key.<br />
<br />
The advantages of the new JS based web tracker are numerous, but the biggest one is that you no longer need an IFrame to your X2 installation! The tracker tracks on your web servers domain now, which removed a lot of the hassle involved with getting the tracker to function properly.<br />
=== Duplicate Handling ===<br />
The basic script doesn't have any sort of handling for finding people who submit the form more than once. Instead of simply creating duplicate records, you can do a few little tricks to make this part of the lead script smarter. First things first, we need a way to check for a duplicate Contact. Before you set any attributes on the Contact model which is the code that has: <tt>foreach($attributes as $key=>$value){</tt> you'll want to add this:<br />
<syntaxhighlight lang="php"><br />
$contact->email=$attributes['email'];<br />
$contact->contactLookup();<br />
if($contact->responseCode!='404'){<br />
// Code to handle duplicates here.<br />
}<br />
</syntaxhighlight><br />
<br />
First, we set the email of the Contact because that's the primary way to look for duplicates. Then we call the "contactLookup" function which does exactly what it says--looks up a Contact. If we can't find any, the response code will be a 404. So all we do then is make our if statement check if the response was something other than a 404 and handle the duplicate in here! There's a few different ways we can deal with that. '''All of the code in the following blocks starts at the response code check.''' The first is a simple redirect, ignoring the duplicate record, which would look like this:<br />
<syntaxhighlight lang="php"><br />
if($contact->responseCode!='404'){<br />
Header("Location: host.domain");<br />
}<br />
</syntaxhighlight><br />
Replacing "host.domain" with your own redirect location. The next step is a little more advanced, which would be to instead detect empty fields in the Contact record and fill them with any submitted data, while preserving data already on the record. The code to do that would look something more like this:<br />
<syntaxhighlight lang="php"><br />
if($contact->responseCode!='404'){<br />
foreach($attributes as $key => $value){ // Try to set any empty attributes<br />
if(isset($fieldMap[$key]) && empty($contact->{$fieldMap[$key]})){ // Check if value is empty + found in field map<br />
$contact->{$fieldMap[$key]} = $value; // Found in field map, used mapped attribute<br />
}elseif(empty($contact->$key)){ // Just check if value is empty<br />
$contact->$key = $value; // No match in field map, assume it's a Contact attribute<br />
}<br />
}<br />
$contact->contactUpdate();<br />
}<br />
</syntaxhighlight><br />
=== Adding Tags ===<br />
=== Lead Logging ===<br />
=== Custom Redirects ===<br />
== Advanced Final Product ==<br />
With all the bells and whistles!<br />
TODO: Add this</div>Jake