3 Replies Latest reply on Feb 5, 2018 12:00 PM by Ambika Sowmyan

    Fetching email contents from API

    Michael Tyson

      I'm working on a portion of our CRM integration with Marketo which requires us to store the contents of an email in Marketo.


      What I'm doing here is caching the activity feed and then in the CRM, pull any related email activities from that cache to show our employees that this contact was recently emailed. From there they want to be able to view the contents of the email itself.


      I pull down a list of all emails available in Marketo from /rest/asset/v1/emails.json which I store. Then I loop over those and pull the contents of that meta data from /rest/asset/v1/email/[email id]/content.json.


      The problem I'm having is that the data returned from content.json is a large array with all the components of the email broken out in to objects. With 'fancy' emails I will essentially need to convert that to an HTML doc which will a) draw out development time significantly and b) be unlikely to look like what we actually sent to customers.


      My question - is there a way to pull the body in a way that I don't need to flatten and parse the array to HTML? Eg, the body itself, already arranged rather than the components or modules of the body.

        • Re: Fetching email contents from API
          Sanford Whiteman

          Marketo email assets are highly dynamic, and there's no way to reproduce the rendered email as sent to the lead, which can depend on a host of dynamic factors (segment membership, field values, and custom Velocity scripting).  The Asset API is meant to manage the framework of email templates and emails, not to obtain individual copies.


          I'd suggest you're going about this the wrong way: if you want to reference sent emails (a massive amount of data) you turn on Marketo's BCC: option and copy those emails to an internal database.

          1 of 1 people found this helpful
            • Re: Fetching email contents from API
              Michael Tyson

              I'll look in to the BCC option, thank you.


              To clarify, I'm not looking for the email itself that was sent to the customer, just the approved email asset in the campaign.

              IE, the following would be completely acceptable to display in the CRM verbatim:

              Dear {{lead.First Name:default=Friend}},


              We are pleased to inform you that you have been accepted at Hogwarts School of Witchcraft and Wizardry. Please find enclosed a list of all necessary books and equipment. Term begins on September 1. We await your owl by no later than July 31.


              Yours sincerely,

              Minerva McGonagall

              Deputy Headmistress


              That particular example is quite easy to store, as it is just text so I don't need to reconstruct the doc. What I was hoping to accomplish was to get the email asset with template variables and any rich content in the CRM.