Export all the Flow steps of a Smart Campaign to a file

Here’s another UI hack to back up parts of Marketo you can’t get any other way. It follows in the footsteps of getting all fields + descriptions and getting all channels + tags. (And like those, it’s a bit extreme for the official Marketo Products blog, so it’s only posted here.)

This time we’re getting the Flow steps of a Smart Campaign, which are — to my continuing frustration — not available via API, even though SC Smart Lists are exportable (?!).

Open F12 Console and make sure you have the inner IFRAME selected (click the Select Element arrow and select anything in the right pane, you don’t actually have to focus the Flow tab itself). Then run:

{
  const commonFetchOptions = {
    method : "POST",
    credentials : "same-origin",
    headers : {
      "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8",
      "X-Requested-With" : "XMLHttpRequest"
    }
  };

  const editFlowEP = "/smartcampaigns/editFlowRS";
  const smartCampaignId = MktCanvas.activeTab.config.compId;
  const xsrfId = MktSecurity.getXsrfId();

  fetch(editFlowEP, 
    Object.assign( 
      commonFetchOptions, 
      { body: `accessZoneId=1&isRequest=1&ajaxHandler=MktCanvas&smartCampaignId=${smartCampaignId}&xsrfId=${xsrfId}` } 
  ) )
  .then( respJ => respJ.json() )
  .then( resp => { 
    const downloadable = JSON.stringify(resp.JSONResults.appvars, null, 2);
    const downloader = document.createElement("a");
    downloader.href = window.URL.createObjectURL( 
      new Blob( [downloadable],{ type:"application/json" } ) 
    );
    downloader.download = `campaign-${smartCampaignId}-flow-steps.json`;
    document.body.appendChild(downloader);
    downloader.click();
  });
}

That’ll export the Flow tab to a file you can open in a JSON viewer (you do have one, right?). Now you can tell management Yes, we do back stuff up before making changes. Or that you know how to, at least.