Extend Marketo Business Logic with Google Cloud Functions

This article proposes a solution to extend Marketo with some business logic capabilities with Google Cloud Platform (GCP), based on the following simple example:

3 custom fields on the Marketo Lead record:

  • OnLinePreference: an incremental score that indicates a prospect/customer appetence for online communications.
  • OfflinePreference: an incremental score that indicates a prospect/customer appetence for offline communications.
  • Preference: a field computed by GCP that displays “offline’ if the offline score is higher than the online one, and “online” the other way around


This technology opens the way for more advanced business logic and eventually for calling out external web services, transforming and consolidating the results in Marketo.

About Google Cloud Platform and Functions


Google Cloud Platform (GCP) is a suite of cloud computing services that runs on the same infrastructure that Google uses internally for its end-user products, such as Google Search and YouTube. Alongside a set of management tools, it provides a series of modular cloud services including computing, data storage, data analytics, machine learning, big data and much more.

We could have used many different GCP services for our need, such as Compute Engine, App Engine or Kubernetes Engine, but we opted for the Cloud Functions (still in Beta) for the following main advantages:

  • Serverless cloud computing where logic can be spun up on-demand in response to events such as HTTP calls.
  • Relieves most of the pain caused by server maintenance and deployments.
  • Cost effective, as you pay GCP only for each function call and not for keeping a server up and running.
  • Simple and fast to implement as you focus only on your application logic.
  • Automatic scaling, ready for very high workloads.

Please check GCP web site for more information about this technology and its pricing. Typically, this tutorial should not induce any important cost and will fit perfectly within the free credit of a GCP trial.

Preparation of your Google Cloud environment

You need a Google Cloud account. You can try GCP for free with a credit that is more than enough to run this tutorial, just click “Try it free” button on the GCP web site.

Follow all the steps from the section ‘Before you begin’ in the HTTP Tutorial from Google:

  1. Create a Cloud Platform project: GO TO THE MANAGE RESOURCES PAGE
    • GCPFunctions1
  2. Enable billing for your project: ENABLE BILLING
  3. Enable the Cloud Functions API: ENABLE THE API
  4. Install and initialize the Cloud SDK
  5. Update and install gcloud components
    gcloud components update &&

    gcloud components install beta

  6. Prepare your environment for Node.js development: GO TO THE SETUP GUIDE

Implementation of the scoreCompare Cloud Function

    1. Create a Cloud Storage bucket to stage your Cloud Functions files. You can do it with the command line:
      gsutil mb gs://[YOUR_STAGING_BUCKET_NAME]

      or from the Google Cloud web interface, by selecting your project and clicking the Storage menu:

      • Give your Storage bucket a unique name
      • Select the default storage class
      • Select the best suited regional locationGCPFunctions4
    2. Create a directory on your local system for the application code.
    3. Create an ‘index.js’ file in this directory with the following JavaScript code: the code is really simple to understand. It parses the two input parameters from the HTTP request body in JSON, does the processing and encodes in JSON the HTTP response.


 * HTTP scoreCompare Cloud Function.
 * @param {Object} req Cloud Function request context.
 * @param {Object} res Cloud Function response context.
exports.scoreCompare = function scoreCompare (req, res) {
 var onlineScore=parseInt(req.body.onlineScore);
 var offlineScore=parseInt(req.body.offlineScore); 
 console.log('/scoreCompare: got values onlineScore =' + onlineScore + ', offlineScore =' + offlineScore);
 var result;
 if (onlineScore>offlineScore) {result = 'online';} else {result = 'offline';}
 console.log('/scoreCompare: and result is ' + result);
 res.status(200).json({output: result}).end();

Deploy the function scoreCompare with an HTTP trigger. Run the following command from your directory:

gcloud beta functions deploy [FUNCTION] –stage-bucket [YOUR_STAGING_BUCKET_NAME] –trigger-http

where [YOUR_STAGING_BUCKET_NAME] is the name of your staging Cloud Storage bucket.

In our example:

gcloud beta functions deploy scoreCompare –stage-bucket mktostorage –trigger-http
  1. Note the Cloud Function URL (httpsTrigger URL) from the console output, that looks like this: https://%5BYOUR_REGION%5D-%5BYOUR_PROJECT_ID%5D.cloudfunctions.net/%5BFUNCTION%5D where
    • [YOUR_REGION] is the region where your function is deployed. This is visible in your terminal when your function finishes deploying.
    • [YOUR_PROJECT_ID] is your Cloud project ID. This is visible in your terminal when your function finishes deploying.
    • [FUNCTION] is your function name.

    In our example:


  2. Test your function with a tool like Postman:

Call the Cloud Function from a Marketo’s Webhook

The three following custom fields must be created on the Lead record in Marketo:

  • OnlinePreference: Integer
  • OfflinePreference: Integer
  • Preference: String

Create the following webhook from the Marketo admin interface by using your ‘scoreCompare’ cloud function URL and the custom field’s tokens:


Test the webhook with a Marketo triggered smart campaign. A smart list and flow are showed here after, as an example:



  • Marketo webhooks can only be invoked from triggered smart campaigns, not batch smart campaigns.
  • If you do not use your cloud function, delete it or delete the whole project, in order to avoid incurring charges to your Google Cloud Platform account.


We hope this tutorial was worth your time and that it will make you think about more advanced scenarios involving complex processing and 3rd party services.

A good example would be to leverage Google Cloud AI, the machine learning services from Google. You could, for example, parse some free text from a Marketo form and ask Google Natural Language API to reveal the structure and meaning of the text and then save back this analysis in Marketo; just opening the floodgates for ideas.