{"_id":"55c7917eb9aa4e0d0016c3a0","parentDoc":null,"category":{"_id":"55c182616d7d2921006da013","pages":["55c184d1c6e9ad3700aaea9c","55c18618c0777c0d004676e1","55c7917eb9aa4e0d0016c3a0"],"version":"55aa7d983be8f60d00041d45","__v":3,"project":"55aa7d973be8f60d00041d42","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-08-05T03:26:25.875Z","from_sync":false,"order":1,"slug":"javascript-api","title":"Javascript API"},"project":"55aa7d973be8f60d00041d42","user":"55aa7d625d3abb0d0012f3da","githubsync":"","version":{"_id":"55aa7d983be8f60d00041d45","__v":20,"project":"55aa7d973be8f60d00041d42","createdAt":"2015-07-18T16:23:52.273Z","releaseDate":"2015-07-18T16:23:52.273Z","categories":["55aa7d983be8f60d00041d46","55aacf4e3be8f60d00041d89","55aacfaae2bdcb0d00c7466e","55aacfb3e2bdcb0d00c7466f","55aacfca3be8f60d00041d8a","55b67da3f8105a2f00c351ab","55b7cae4aea7c8190058ba5b","55b9218afeef5135009b7db3","55c182616d7d2921006da013","5631407afa40240d007c8c60","56548b9c9c4c6d0d00aeda0c","572b9137ff3ba10e00b4abb4","572b9150ff3ba10e00b4abb5","581b83288ca41f0f007e4fb6","585065fa70cbe00f00835bb8","58641eba0355f31900380492","58861760b4816e19005c9941","58a316cb254c401b00a049ce","58ac80dbd5e1570f00d1c328","59f72b4991121a00104f036e"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":10,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-08-09T17:44:30.389Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"If you are implementing your own wesite, you can easily save data user's leave in your Forms by using our JavaScript API.\n\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\tLeadaki.saveContact({\\n\\t\\tfirst_name : 'Morgan',\\n\\t\\tlast_name : 'Freeman',\\n    full_name : 'Morgan Freeman',\\n\\t\\tphone : '+541133261336',\\n\\t\\tmobile : '+5491140546578',\\n\\t\\temail : 'mariano:::at:::cliengo.com',\\n\\t\\tmessage : 'Hi, i want to buy a car \\\\n Please call me.',\\n\\t\\taddress : '',\\n\\t\\ttags : '', // coma separated tags\\n\\t\\ttracking : { // override automatic tracking.\\n\\t\\t\\tutm_source: '',\\n\\t\\t\\tutm_medium : '',\\n\\t\\t\\tutm_campaign: '',\\n\\t\\t\\tutm_content : '',\\n\\t\\t\\tgclid : '', // Google AdWords clickId\\n\\t\\t\\tcontact_method : '', // form, chat or phone.\\n\\t\\t},\\n\\t\\tcustom_fields: { //Any key-value pair you want to store\\n\\t\\t\\tsome_key1 : \\\"some_value1\\\",\\n\\t\\t\\tsome_key2 : \\\"some_value2\\\",\\n\\t  },\\n    success : function (data){\\n      //handler after Contact is successfully saved.\\n    },\\n    error : function (data){\\n      //handler if something went wrong when saving Contact.\\n    }\\n\\t})\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n**All fields are Optional**, but in order to save any valid Contact in Cliengo Data Base you should provide at least one combination of email, phone o mobile with data.\n\nBelow the explanation of every field:\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"first_name\",\n    \"0-1\": \"Contact's first name.\",\n    \"1-0\": \"last_name\",\n    \"2-0\": \"full_name\",\n    \"1-1\": \"Contact's last name.\",\n    \"2-1\": \"Use this field en case you dont have first and lastname splited in two fields.\",\n    \"3-0\": \"phone\",\n    \"4-0\": \"mobile\",\n    \"5-0\": \"email\",\n    \"6-0\": \"message\",\n    \"7-0\": \"address\",\n    \"8-0\": \"tags\",\n    \"8-1\": \"Coma separated strings for tagging your Contact.\",\n    \"9-0\": \"tracking\",\n    \"9-1\": \"Tracking information about your Contact. This fields are automatically tracked with  [Cliengo AutoTracking ](http://help.cliengo.com/support/solutions/articles/17000000033-track-autom%C3%A1tico-de-fuente-y-medio) but you can override them with this option.\",\n    \"10-0\": \"custom_fields\",\n    \"10-1\": \"Any key-value pair you want to store in this Contact\",\n    \"11-0\": \"success\",\n    \"11-1\": \"Function handler that executes after Contact is successfully saved in Cliengo Database.\",\n    \"12-0\": \"error\",\n    \"12-1\": \"Function handler if something went wrong when saving Contact in Cliengo Database.\",\n    \"7-1\": \"Contact's address. Free string where you can include zipcode, city, street, number, state or country.\",\n    \"6-1\": \"Contact's mesage. Usually your Contact's question, doubt or message.\",\n    \"5-1\": \"Contact's email.\",\n    \"4-1\": \"Contact's mobile phone number.\",\n    \"3-1\": \"Contact's phone number.\"\n  },\n  \"cols\": 2,\n  \"rows\": 13\n}\n[/block]\n## Duplicated Contacts:\n\nCliengo Data Base will automatically merge new Contacts with the same email address in your account, and will also eliminate duplicated messages when information is exactly the same.\nThis means that you dont have to worry about users submiting information multiple times in your webiste. Cliengo Data Base will take care of it.\n\n\n## Working example \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<!-- This is your Website Form -->\\n<form action=\\\"\\\" onsubmit=\\\"return mySubmitFunction()\\\">\\n  <input type=\\\"text\\\" name=\\\"fullName\\\" id=\\\"fullName\\\" value=\\\"John Doe\\\"> \\n  <input type=\\\"text\\\" name=\\\"email\\\" id=\\\"email\\\" value=\\\"email@company.com\\\"> \\n  <input type=\\\"text\\\" name=\\\"phone\\\" id=\\\"phone\\\" value=\\\"+1 555-5555\\\">\\n  <textarea type=\\\"text\\\" name=\\\"message\\\" id=\\\"message\\\">\\n    Lorem impsum...\\n  </textarea>\\n  <input type=\\\"submit\\\" value=\\\"Send Information\\\">\\n</form>\\n\\n\\n<!-- This is your Script for saving Contacts -->           \\n<script>\\n  function mySubmitFunction() {\\n    Leadaki.saveContact({\\n      full_name : document.getElementById(\\\"fullName\\\").value,\\n      phone : document.getElementById(\\\"phone\\\").value,\\n      email : document.getElementById(\\\"email\\\").value,\\n      message : document.getElementById(\\\"message\\\").value,\\n      success : function() {\\n        alert(\\\"Contact was successfully saved!\\\");\\n      },\\n      error : function() {\\n        alert(\\\"There was a problem. Try again later.\\\");\\n      }\\n    })\\n    return false;\\n  }\\n</script>\\n\\n<!-- Reminder: you need your Cliengo Instalation Script pasted somewhere in this page -->\\n\\n\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]","excerpt":"Save new contacts in Cliengo Data Base","slug":"javascript-api-saving-contacts","type":"basic","title":"Saving Contacts"}

Saving Contacts

Save new contacts in Cliengo Data Base

If you are implementing your own wesite, you can easily save data user's leave in your Forms by using our JavaScript API. [block:code] { "codes": [ { "code": "\tLeadaki.saveContact({\n\t\tfirst_name : 'Morgan',\n\t\tlast_name : 'Freeman',\n full_name : 'Morgan Freeman',\n\t\tphone : '+541133261336',\n\t\tmobile : '+5491140546578',\n\t\temail : 'mariano@cliengo.com',\n\t\tmessage : 'Hi, i want to buy a car \\n Please call me.',\n\t\taddress : '',\n\t\ttags : '', // coma separated tags\n\t\ttracking : { // override automatic tracking.\n\t\t\tutm_source: '',\n\t\t\tutm_medium : '',\n\t\t\tutm_campaign: '',\n\t\t\tutm_content : '',\n\t\t\tgclid : '', // Google AdWords clickId\n\t\t\tcontact_method : '', // form, chat or phone.\n\t\t},\n\t\tcustom_fields: { //Any key-value pair you want to store\n\t\t\tsome_key1 : \"some_value1\",\n\t\t\tsome_key2 : \"some_value2\",\n\t },\n success : function (data){\n //handler after Contact is successfully saved.\n },\n error : function (data){\n //handler if something went wrong when saving Contact.\n }\n\t})", "language": "javascript" } ] } [/block] **All fields are Optional**, but in order to save any valid Contact in Cliengo Data Base you should provide at least one combination of email, phone o mobile with data. Below the explanation of every field: [block:parameters] { "data": { "0-0": "first_name", "0-1": "Contact's first name.", "1-0": "last_name", "2-0": "full_name", "1-1": "Contact's last name.", "2-1": "Use this field en case you dont have first and lastname splited in two fields.", "3-0": "phone", "4-0": "mobile", "5-0": "email", "6-0": "message", "7-0": "address", "8-0": "tags", "8-1": "Coma separated strings for tagging your Contact.", "9-0": "tracking", "9-1": "Tracking information about your Contact. This fields are automatically tracked with [Cliengo AutoTracking ](http://help.cliengo.com/support/solutions/articles/17000000033-track-autom%C3%A1tico-de-fuente-y-medio) but you can override them with this option.", "10-0": "custom_fields", "10-1": "Any key-value pair you want to store in this Contact", "11-0": "success", "11-1": "Function handler that executes after Contact is successfully saved in Cliengo Database.", "12-0": "error", "12-1": "Function handler if something went wrong when saving Contact in Cliengo Database.", "7-1": "Contact's address. Free string where you can include zipcode, city, street, number, state or country.", "6-1": "Contact's mesage. Usually your Contact's question, doubt or message.", "5-1": "Contact's email.", "4-1": "Contact's mobile phone number.", "3-1": "Contact's phone number." }, "cols": 2, "rows": 13 } [/block] ## Duplicated Contacts: Cliengo Data Base will automatically merge new Contacts with the same email address in your account, and will also eliminate duplicated messages when information is exactly the same. This means that you dont have to worry about users submiting information multiple times in your webiste. Cliengo Data Base will take care of it. ## Working example [block:code] { "codes": [ { "code": "<!-- This is your Website Form -->\n<form action=\"\" onsubmit=\"return mySubmitFunction()\">\n <input type=\"text\" name=\"fullName\" id=\"fullName\" value=\"John Doe\"> \n <input type=\"text\" name=\"email\" id=\"email\" value=\"email@company.com\"> \n <input type=\"text\" name=\"phone\" id=\"phone\" value=\"+1 555-5555\">\n <textarea type=\"text\" name=\"message\" id=\"message\">\n Lorem impsum...\n </textarea>\n <input type=\"submit\" value=\"Send Information\">\n</form>\n\n\n<!-- This is your Script for saving Contacts --> \n<script>\n function mySubmitFunction() {\n Leadaki.saveContact({\n full_name : document.getElementById(\"fullName\").value,\n phone : document.getElementById(\"phone\").value,\n email : document.getElementById(\"email\").value,\n message : document.getElementById(\"message\").value,\n success : function() {\n alert(\"Contact was successfully saved!\");\n },\n error : function() {\n alert(\"There was a problem. Try again later.\");\n }\n })\n return false;\n }\n</script>\n\n<!-- Reminder: you need your Cliengo Instalation Script pasted somewhere in this page -->\n\n", "language": "html" } ] } [/block]