Created
March 27, 2014 12:30
Revisions
-
torpio revised this gist
Aug 7, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -57,9 +57,9 @@ if (!validFieldMappings) { // Update the lead service.post('flg360', 'APILeadCreateUpdate.php', input, function (error, status, result) { if (error) { log.error("Couldn't update the lead.", input, error); } else if (status >= 500 || result.indexOf('<status>0</status>') === -1) { log.error("Couldn't update the lead.", input, result); } else { log.info("Updated the lead.", result); } -
torpio revised this gist
Mar 28, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,11 +39,11 @@ if (!validFieldMappings) { var data = JSON.parse(helper.template(settings.field_mappings || '{}', request.body)); data.id = request.body.id; //////////////////// MANIPULATE 'data' HERE IF NECESSARY //////////////////// ///////////////////////////////////////////////////////////////////////////// // Build the lead update in FLG 360 var input = "<data><lead>"; -
torpio revised this gist
Mar 28, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,7 +43,7 @@ if (!validFieldMappings) { /////////////////////////////////////////////////////////////////////////// // Build the lead update in FLG 360 var input = "<data><lead>"; -
torpio revised this gist
Mar 28, 2014 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,6 +39,12 @@ if (!validFieldMappings) { var data = JSON.parse(helper.template(settings.field_mappings || '{}', request.body)); data.id = request.body.id; //////////////////// MANIPULATE data HERE IF NECESSARY //////////////////// //////////////////// MANIPULATE data HERE IF NECESSARY //////////////////// // Build the lead update in FLG 360 var input = "<data><lead>"; -
torpio revised this gist
Mar 27, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ be any value received by the webhook (broadly the same as those available throug var settings = {}; // A simple JSON object of field mappings. e.g. { "field": "value" }. You can use curly bracket templating to insert any {{value}} from the FLG 360 webhook, for example {{data1}}. settings.field_mappings = "" try { JSON.parse(settings.field_mappings || '{}'); -
torpio created this gist
Mar 27, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ /* This script receives a webhook from FLG 360 and updates the same lead based on the values received. For example, to update the field ```data1``` with the date/time of the webhook, you might use a field mapping like this: { "data1": "{{eventdatetime}}" } The field can be any of those available in FLG 360's [Lead Create & Update API](http://flg360.uservoice.com/knowledgebase/articles/332566-api-documentation). The template values can be any value received by the webhook (broadly the same as those available through the API), plus: - eventtype - eventdatetime */ var settings = {}; // A simple JSON object of field mappings. e.g. { "field": "value" }. You can use curly bracket templating to insert any {{value}} from the FLG 360 webhook, for example {{data1}}. settings.field_mappings = "x" try { JSON.parse(settings.field_mappings || '{}'); var validFieldMappings = true; } catch (error) { var validFieldMappings = false; } if (!validFieldMappings) { log.error("The field mappings doesn't seem to be valid JSON. Have you enclosed all properties in quotes?"); } else if (!request.body) { log.error("You should call this script from a FLG 360 webhook. We didn't receive any data."); } else { // Create the data object from the template var data = JSON.parse(helper.template(settings.field_mappings || '{}', request.body)); data.id = request.body.id; // Build the lead update in FLG 360 var input = "<data><lead>"; _.each(data, function (value, key) { input += "<" + key + ">" + XML.safe(value) + "</" + key + ">"; }); input += "</lead></data>"; // Update the lead service.post('flg360', 'APILeadCreateUpdate.php', input, function (error, status, result) { if (error) { log.error("Couldn't update the lead.", error); } else if (status >= 500 || result.indexOf('<status>0</status>') === -1) { log.error("Couldn't update the lead.", result); } else { log.info("Updated the lead.", result); } }); } // Install with #torpio at https://torpio.com/app/scripts/shared/view/33276