{"id":1468,"date":"2014-07-06T23:05:35","date_gmt":"2014-07-07T05:05:35","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/?p=1468"},"modified":"2014-07-06T23:11:02","modified_gmt":"2014-07-07T05:11:02","slug":"building-an-automated-postcard-system-with-lob-and-zapier","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/1468","title":{"rendered":"Building an automated postcard mailing system with Lob and Zapier"},"content":{"rendered":"<figure id=\"attachment_1481\" aria-describedby=\"caption-attachment-1481\" style=\"width: 240px\" class=\"wp-caption alignleft\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1481 size-full\" src=\"http:\/\/www.mooreds.com\/wordpress\/wp-content\/uploads\/2014\/07\/2304203049_c7297bb07c_m.jpg\" alt=\"Courtesy of smoothfluid\" width=\"240\" height=\"154\" \/><figcaption id=\"caption-attachment-1481\" class=\"wp-caption-text\">Courtesy of <a href=\"https:\/\/www.flickr.com\/photos\/smoothfluid\/2304203049\/\">smoothfluid<\/a><\/figcaption><\/figure>\n<p>I was looking at automated paper mailing systems recently (and <a href=\"http:\/\/stackoverflow.com\/a\/19127822\/203619 \">listed what I found<\/a>), and was especially impressed with <a href=\"https:\/\/www.lob.com\/docs\">Lob<\/a>, especially the ease of its API.<\/p>\n<p>Among other printing services, Lob will let you mail a postcard with a custom PDF on both sides, or a custom PDF on one side and a text message on the other, anywhere in the USA for $0.94. \u00a0(Sorry, not sure about international postcards) The company for which I work sends out tens of thousands of postcards every quarter. The vendor which we use charges them a similar fee (less, but in the same ballpark) but there&#8217;s a manual process to deliver the collateral and no API. So an on-demand, one by one post card sending system is very interesting to me.<\/p>\n<p>Note that I haven&#8217;t received the Lob postcard which I sent myself, so I can&#8217;t speak to quality. Yet.<\/p>\n<p>The Lob API is a bit weird, because the request is form encoded rather than a JSON payload. \u00a0It also uses basic auth, but only the username, not the password. But the API seems to have all the pieces you&#8217;d need to generate all kinds of postcards&#8211;reminder postcards, direct mail postcards, photo postcards, etc.<\/p>\n<p>After testing out the service via the web interface and <a href=\"http:\/\/curl.haxx.se\/\">cURL<\/a> examples, I thought that it&#8217;d be fun to build a <a href=\"http:\/\/zapier.com\">Zapier<\/a> zap. In particular, being able to send a postcard for an entry in a Google spreadsheet seemed like a useful use case. Plus, <a href=\"\/wordpress\/archives\/1461\">Zapier is awesome<\/a>, and I&#8217;d wanted to test out their integration environment for myself.<\/p>\n<p>So, I built a Zapier integration for Lob, using the <a href=\"https:\/\/zapier.com\/developer\/documentation\/reference\/\">Zapier developer docs<\/a> in combination with the <a href=\"https:\/\/www.lob.com\/docs\">Lob developer docs<\/a>. It was actually easy. The most complicated step was translating the Zapier action data, which is a one or two dimensional array of typed data, into the Lob data format, which wanted a couple of text fields and two address arrays. Zapier has a <a href=\"https:\/\/zapier.com\/developer\/documentation\/scripting\/\">scripting environment<\/a> that let me modify data from APIs pre and post send, and even had an example about form encoded APIs. Zapier&#8217;s JavaScript scripting development environment was full featured, including syntax and error highlighting. It had no real debugging available, but I could use the venerable debug-by-log-statement method fairly easily.<\/p>\n<p>Where could I take this next? Everywhere people use postcards in real life. The postcards depend on PDF files (see a <a href=\"https:\/\/www.lob.com\/postcardfront.pdf\">sample<\/a>), so if you are generating a custom postcard for each interaction things become more complex, but there are a few APIs (based on a 30 second google search, <a href=\"http:\/\/pdfcrowd.com\/html-to-pdf-api\/\">here<\/a> and <a href=\"https:\/\/docraptor.com\/\">here<\/a>) available for dynamic PDF generation. There are also limits on API call throughput, if I\u00a0stuck to the Zapier integration&#8211;I could send at most 300 postcards a day, unless I managed multiple spreadsheets.<\/p>\n<p>I see reminders of high value events (dentist, house maintenance, etc), contests and marketing as key opportunities\u00a0for this type of service. And if I had a product where direct mail was a key component, using Lob directly would be worth serious consideration.<\/p>\n<p>Regarding the Zap, I believe I cannot make this Zap available to anyone else. Since I&#8217;m not a representative of Lob, I couldn&#8217;t commit to maintaining this Zap, and Zapier doesn&#8217;t want to have any of their customers depending on an integration that could disappear or be unsupported at any time&#8211;a fair position.<\/p>\n<p>If the Zapier or Lob folks want to take this integration and run with it, I&#8217;d be happy to share my code&#8211;just leave a comment. If anyone else is interested in being able to generate Lob postcards from a Google spreadsheet (or any other compatible API) via Zapier integration, let me know and I&#8217;ll see what I can do.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was looking at automated paper mailing systems recently (and listed what I found), and was especially impressed with Lob, especially the ease of its API. Among other printing services, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62,65,35,54,33],"tags":[],"class_list":["post-1468","post","type-post","status-publish","format-standard","hentry","category-apis","category-bpa","category-business","category-javascript","category-useful-tools"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1468","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1468"}],"version-history":[{"count":14,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1468\/revisions"}],"predecessor-version":[{"id":1476,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1468\/revisions\/1476"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}