{"__v":16,"_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":true,"order":4,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Variables in emails\"\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    \"3-0\": \"!!!RECIPIENT_NAME!!!\",\n    \"3-1\": \"*Mixmax Intern*\",\n    \"3-2\": \"The full name of the person you're emailing. Will be blank if there is no name associated with the email address.\",\n    \"4-0\": \"!!!RECIPIENT_NAME_URL!!!\",\n    \"4-1\": \"*Mixmax%20Intern*\",\n    \"4-2\": \"URL-encoded version of the name. Useful for URL query strings.\",\n    \"5-0\": \"!!!SENDER_EMAIL!!!\",\n    \"5-1\": \"*hugo@brockman.com*\",\n    \"5-2\": \"Email address of the sender.\",\n    \"6-0\": \"!!!SENDER_EMAIL_URL!!!\",\n    \"6-1\": \"*hugo%40brockman.com*\",\n    \"6-2\": \"URL-encoded email address of the sender.\",\n    \"2-0\": \"!!!MESSAGE_ID!!!\",\n    \"2-1\": \"JeZ31UW0sVOFNbNYU\",\n    \"2-2\": \"The _id of the message (that can be fetched via the API)\"\n  },\n  \"cols\": 3,\n  \"rows\": 7\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\": \"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 emails" } [/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.", "3-0": "!!!RECIPIENT_NAME!!!", "3-1": "*Mixmax Intern*", "3-2": "The full name of the person you're emailing. Will be blank if there is no name associated with the email address.", "4-0": "!!!RECIPIENT_NAME_URL!!!", "4-1": "*Mixmax%20Intern*", "4-2": "URL-encoded version of the name. Useful for URL query strings.", "5-0": "!!!SENDER_EMAIL!!!", "5-1": "*hugo@brockman.com*", "5-2": "Email address of the sender.", "6-0": "!!!SENDER_EMAIL_URL!!!", "6-1": "*hugo%40brockman.com*", "6-2": "URL-encoded email address of the sender.", "2-0": "!!!MESSAGE_ID!!!", "2-1": "JeZ31UW0sVOFNbNYU", "2-2": "The _id of the message (that can be fetched via the API)" }, "cols": 3, "rows": 7 } [/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": "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`.