{"__v":15,"_id":"56427cbff2d7740d00130c8b","category":{"__v":0,"_id":"57f55187440418170086325a","project":"5588b8a2f6c18d0d005bba03","version":"5588b8a2f6c18d0d005bba06","sync":{"url":"","isSync":false},"reference":true,"createdAt":"2016-10-05T19:16:23.805Z","from_sync":false,"order":1,"slug":"integrations","title":"Integration API"},"parentDoc":null,"project":"5588b8a2f6c18d0d005bba03","user":"5588b847f6c18d0d005bba01","version":{"__v":14,"_id":"5588b8a2f6c18d0d005bba06","project":"5588b8a2f6c18d0d005bba03","createdAt":"2015-06-23T01:38:42.696Z","releaseDate":"2015-06-23T01:38:42.696Z","categories":["5588b8a3f6c18d0d005bba07","5588e9689cfea70d00371df3","5588f5921163180d00b64704","561598b121e9110d0078025a","5616f1c9d170d00d00189306","5616f5c3a410c90d00c6121e","561803dcf8c9632100ac7592","563667280441020d0000e9eb","5642570d9417b40d00c0fcd3","57bf5f02efe0050e00d50bd5","57f53fb368a53b2000e03f0f","57f55187440418170086325a","582e3afa72fd270f0006926d","5841faa973967b0f004b4a2b"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-11-10T23:24:47.694Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Variables in templates\"\n}\n[/block]\nHTML content passed back from the resolver URLs can contain the following \"magic strings\" that will be replaced when the email is sent:\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"!!!EMAIL_ADDR!!!\",\n    \"h-0\": \"String variable name\",\n    \"h-1\": \"Example\",\n    \"0-1\": \"*intern:::at:::mixmax.com*\",\n    \"0-2\": \"The email address of the user the email is being sent to. If the email is being sent to multiple recipients, each recipients's email will still be encoded in the individual copy of the email they receive (even though they still see the email was sent 'to' all recipients).\",\n    \"h-2\": \"Meaning\",\n    \"1-0\": \"!!!EMAIL_ADDR_URL!!!\",\n    \"1-1\": \"*intern%40mixmax.com*\",\n    \"1-2\": \"URL-encoded email address of the recipient. Useful for URL query strings.\",\n    \"2-0\": \"!!!RECIPIENT_NAME!!!\",\n    \"2-1\": \"*Mixmax Intern*\",\n    \"2-2\": \"The full name of the person you're emailing. Will be blank if there is no name associated with the email address.\",\n    \"3-0\": \"!!!RECIPIENT_NAME_URL!!!\",\n    \"3-1\": \"*Mixmax%20Intern*\",\n    \"3-2\": \"URL-encoded version of the name. Useful for URL query strings.\",\n    \"4-0\": \"!!!SENDER_EMAIL!!!\",\n    \"4-1\": \"*hugo@brockman.com*\",\n    \"4-2\": \"Email address of the sender.\",\n    \"5-0\": \"!!!SENDER_EMAIL_URL!!!\",\n    \"5-1\": \"*hugo%40brockman.com*\",\n    \"5-2\": \"URL-encoded email address of the sender.\"\n  },\n  \"cols\": 3,\n  \"rows\": 6\n}\n[/block]\n**Example**\n\nLet's say you're building an SDK integration that inserts a link to initiate a chat between the sender and each recipient. The HTML could look like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<a href=\\\"https://mychatservice.com/createChat?sender=!!!SENDER_EMAIL_URL!!!&recipientEmail=!!!EMAIL_ADDR_URL!!!&recipientName=!!!RECIPIENT_NAME_URL!!!\\\">Let's chat!</a>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\n(notice that here we're using URL-encoded variants of the variables)\n\nThen Mixmax user hugo@brockman.com inserts your chat link and sends an email to two people:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/0iv2KYFFR125Y0tZ5vsh_Screen%20Shot%202015-11-10%20at%203.56.47%20PM.png\",\n        \"Screen Shot 2015-11-10 at 3.56.47 PM.png\",\n        \"1199\",\n        \"402\",\n        \"#5f7bbc\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nWhen the email is sent, Jim Ellis will get:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<a href=\\\"https://mychatservice.com/createChat?sender=hugo%40brockman.com&recipientEmail=jim%40mixmax.com&recipientName=Jim%20Ellis\\\"></a>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nand bradv@mixmax.com will get:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<a href=\\\"https://mychatservice.com/createChat?sender=hugo%40brockman.com&recipientEmail=bradv%40mixmax.com&recipientName=\\\"></a>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nNotice that the recipientName is blank since bradv@mixmax.com doesn't have a name in the 'to' field above.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"\\\"Insecure content https, request blocked\\\" when developing locally\"\n}\n[/block]\nThe tutorials in this guide use local http urls (e.g. http://localhost:9292/resolver) and asks you to test them from Mixmax's compose **window**, which is hosted on https. As a result, you will likely get the following error:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/2052aec-PHc1g6JgTPe2fbfBRcYa_Screen_Shot_2015-11-01_at_11.33.59_AM.png\",\n        \"PHc1g6JgTPe2fbfBRcYa_Screen Shot 2015-11-01 at 11.33.59 AM.png\",\n        2146,\n        308,\n        \"#f6ecec\"\n      ]\n    }\n  ]\n}\n[/block]\nThis happens because Chrome will block http content loaded over https by default. This will not happen in production because your URL will be hosted on an https domain.\n\nIf you'd like to test locally, you have two options:\n\n**Option 1) Run Chrome in insecure mode** \n\nClose Chrome and restart it using the following commands in the terminal. This will tell it to ignore Mixed Content exceptions. Be careful not to leave it in this mode and browse the web, as it will leave you vulnerable.\n\nOn OS X:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"open -a Google\\\\ Chrome --args --allow-running-insecure-content --ignore-certificate-errors\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nOn Windows, you'll need to navigate to the Chrome application directory as described [here](http://www.ghacks.net/2013/10/06/list-useful-google-chrome-command-line-switches/). Then execute:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"chrome.exe --allow-running-insecure-content --ignore-certificate-errors\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n**Option 2) Serve up https locally** \n\nSee instructions [here](http://www.sitepoint.com/how-to-use-ssltls-with-node-js/). Note that you'll need to replace \"http://\" with \"https://\" in the example urls given in these tutorials.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Client-side (AJAX) API Requests\"\n}\n[/block]\nFor several APIs, Mixmax makes an AJAX call directly from the user's browser (via AJAX) to your server, for performance.\n\n**CORS and HTTPS** \n\nYour server needs to be on HTTPS and implement [CORS headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) so your response can be received by the client. See an [example here](https://github.com/mixmaxhq/giphy-mixmax-app/blob/master/server.js#L15) for how to do this in Express/Node.js.\n\n**Time Zones** \n\nRequests include an `x-timezone` header indicating the current user's time zone. The value will be a [time zone name](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) such as `America/Los_Angeles`.","excerpt":"","slug":"variables-in-templates","type":"basic","title":"Appendix"}
[block:api-header] { "type": "basic", "title": "Variables in templates" } [/block] HTML content passed back from the resolver URLs can contain the following "magic strings" that will be replaced when the email is sent: [block:parameters] { "data": { "0-0": "!!!EMAIL_ADDR!!!", "h-0": "String variable name", "h-1": "Example", "0-1": "*intern@mixmax.com*", "0-2": "The email address of the user the email is being sent to. If the email is being sent to multiple recipients, each recipients's email will still be encoded in the individual copy of the email they receive (even though they still see the email was sent 'to' all recipients).", "h-2": "Meaning", "1-0": "!!!EMAIL_ADDR_URL!!!", "1-1": "*intern%40mixmax.com*", "1-2": "URL-encoded email address of the recipient. Useful for URL query strings.", "2-0": "!!!RECIPIENT_NAME!!!", "2-1": "*Mixmax Intern*", "2-2": "The full name of the person you're emailing. Will be blank if there is no name associated with the email address.", "3-0": "!!!RECIPIENT_NAME_URL!!!", "3-1": "*Mixmax%20Intern*", "3-2": "URL-encoded version of the name. Useful for URL query strings.", "4-0": "!!!SENDER_EMAIL!!!", "4-1": "*hugo@brockman.com*", "4-2": "Email address of the sender.", "5-0": "!!!SENDER_EMAIL_URL!!!", "5-1": "*hugo%40brockman.com*", "5-2": "URL-encoded email address of the sender." }, "cols": 3, "rows": 6 } [/block] **Example** Let's say you're building an SDK integration that inserts a link to initiate a chat between the sender and each recipient. The HTML could look like this: [block:code] { "codes": [ { "code": "<a href=\"https://mychatservice.com/createChat?sender=!!!SENDER_EMAIL_URL!!!&recipientEmail=!!!EMAIL_ADDR_URL!!!&recipientName=!!!RECIPIENT_NAME_URL!!!\">Let's chat!</a>", "language": "html" } ] } [/block] (notice that here we're using URL-encoded variants of the variables) Then Mixmax user hugo@brockman.com inserts your chat link and sends an email to two people: [block:image] { "images": [ { "image": [ "https://files.readme.io/0iv2KYFFR125Y0tZ5vsh_Screen%20Shot%202015-11-10%20at%203.56.47%20PM.png", "Screen Shot 2015-11-10 at 3.56.47 PM.png", "1199", "402", "#5f7bbc", "" ] } ] } [/block] When the email is sent, Jim Ellis will get: [block:code] { "codes": [ { "code": "<a href=\"https://mychatservice.com/createChat?sender=hugo%40brockman.com&recipientEmail=jim%40mixmax.com&recipientName=Jim%20Ellis\"></a>", "language": "html" } ] } [/block] and bradv@mixmax.com will get: [block:code] { "codes": [ { "code": "<a href=\"https://mychatservice.com/createChat?sender=hugo%40brockman.com&recipientEmail=bradv%40mixmax.com&recipientName=\"></a>", "language": "html" } ] } [/block] Notice that the recipientName is blank since bradv@mixmax.com doesn't have a name in the 'to' field above. [block:api-header] { "type": "basic", "title": "\"Insecure content https, request blocked\" when developing locally" } [/block] The tutorials in this guide use local http urls (e.g. http://localhost:9292/resolver) and asks you to test them from Mixmax's compose **window**, which is hosted on https. As a result, you will likely get the following error: [block:image] { "images": [ { "image": [ "https://files.readme.io/2052aec-PHc1g6JgTPe2fbfBRcYa_Screen_Shot_2015-11-01_at_11.33.59_AM.png", "PHc1g6JgTPe2fbfBRcYa_Screen Shot 2015-11-01 at 11.33.59 AM.png", 2146, 308, "#f6ecec" ] } ] } [/block] This happens because Chrome will block http content loaded over https by default. This will not happen in production because your URL will be hosted on an https domain. If you'd like to test locally, you have two options: **Option 1) Run Chrome in insecure mode** Close Chrome and restart it using the following commands in the terminal. This will tell it to ignore Mixed Content exceptions. Be careful not to leave it in this mode and browse the web, as it will leave you vulnerable. On OS X: [block:code] { "codes": [ { "code": "open -a Google\\ Chrome --args --allow-running-insecure-content --ignore-certificate-errors", "language": "shell" } ] } [/block] On Windows, you'll need to navigate to the Chrome application directory as described [here](http://www.ghacks.net/2013/10/06/list-useful-google-chrome-command-line-switches/). Then execute: [block:code] { "codes": [ { "code": "chrome.exe --allow-running-insecure-content --ignore-certificate-errors", "language": "shell" } ] } [/block] **Option 2) Serve up https locally** See instructions [here](http://www.sitepoint.com/how-to-use-ssltls-with-node-js/). Note that you'll need to replace "http://" with "https://" in the example urls given in these tutorials. [block:api-header] { "type": "basic", "title": "Client-side (AJAX) API Requests" } [/block] For several APIs, Mixmax makes an AJAX call directly from the user's browser (via AJAX) to your server, for performance. **CORS and HTTPS** Your server needs to be on HTTPS and implement [CORS headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) so your response can be received by the client. See an [example here](https://github.com/mixmaxhq/giphy-mixmax-app/blob/master/server.js#L15) for how to do this in Express/Node.js. **Time Zones** Requests include an `x-timezone` header indicating the current user's time zone. The value will be a [time zone name](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) such as `America/Los_Angeles`.