Re: How to return information from remote API back to the Marketo form

desijadoo
Level 1

How to return information from remote API back to the Marketo form

I'm trying to display the information sent by API call back to the web page that hosts the Marketo form.

Conceptual flow is as follows:

Web page (Marketo Form) --> Form Submit --> call api (pass form fields as input) --> api executes & returns information as output --> map api output fields to variables --> set (hidden) Form field to variable --> display form fields to users on web page.

This works all the way until the last step where display of form field yields no information that was returned by the API call. 

 

My understanding is that API call is Synchronous, so it will wait for the API to execute and return values.

 

I have script written in onSuccess() method to read the form variables and display on web page. (this doesn't work!).

 

I have added wait() function as well to wait for 15 seconds (for testing) hoping it provides enough time for API to execute (which it does within 1/1.5 seconds). Dev Tools Network log shows API returned the values and variables were updated as expected. But these were not available in the onSuccess()  method or I am doing something incorrect.

 

Any help will be appreciated.

 

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: How to return information from remote API back to the Marketo form

What remote API exactly?

 

(By the way, I edited your post. It's better to not call this a "webhook" as webhooks specifically refer to server-to-server communication. If you're consuming a CORS-compatible API from the browser, that's not really a webhook.)

desijadoo
Level 1

Re: How to return information from remote API back to the Marketo form

Thanks for looking into this. I may have used API and webhooks interchangeably.

Remote API is a REST API hosted on remote server that accepts post parameters and processes the data (stores it in database) and returns values back.

Example: a REST API that accepts Material Number and stores it in database and returns Document Title and Document URL pertaining to that material number. 

So my input to API is materialNumber, emailAddress and output JSON contains DocTitle and DocURL.

I call this API within the webhook setup.

 

My Marketo form has following fields: material-number, email-address, (hidden) docTitle, (hidden) docURL.

 

I setup a 'call webhook' in the campaign flow and mapped all the form fields to api via webhook setup screen (URL as remote API, template, request type, response format etc).

 

I then display all form variable values within onSuccess() - which is able to display my input values provided to non-hidden fields but the hidden fields do not get populated back from Webhook call.

 

Wehbook Details:

marketo-WH.jpg

 

Campaign Flow step:

marketo-Flow.png

 

 My Webpage Form script:

marketo-script.jpg

values.rmsWHDocURL and values.rmsWHDocTitle remain empty. 

values.rmsMaterialNumber displays the number entered in the form's material# field.

SanfordWhiteman
Level 10 - Community Moderator

Re: How to return information from remote API back to the Marketo form

You cannot expect Call Webhook-updated fields to be available in the onSuccess! There's no timing guarantee whatsoever; under load, the webhook might not even be called for a couple of minutes after the form post. (EDIT: And in the values argument to onSuccess, those are only the values submitted with the form. Not the fields loaded from the server database.)

The closest you could come is polling the follow-up page for, say, 30 seconds to look for an update. But that's an arbitrary limit to ensure a not-too-bad used experience and doesn't guarantee the client will see the update in that timeframe. You'd still have to send them the info via email as a fallback.

desijadoo
Level 1

Re: How to return information from remote API back to the Marketo form

Thanks, I understand the implication of the timings. (Though when testing this in our sandbox environment, with no load, no concurrent users or any heavy activity, I can see the API returns within 1/1.5 seconds, the activity log of the webhook call shows values were returned and assigned as per the response mapping.)

 

I also setup another trigger campaign to respond to "webhook is called" and in the flow wait for 1 minute followed by change data value to assign the values to variables. Still does not work.

 

Could you please elaborate on "The closest you could come is polling the follow-up page for, say, 30 seconds to look for an update." ? How would one implement this?

 

Does it mean I provide a "refresh/polling" button on the follow up page? if so, the poll button submit calls which form? and since it would be an implicit form fill, I need to prefill it email address from previous form fill etc?

 

On a side note: I think I saw in Marketo documentation, webhook example related to Google's Geo API which returns latitude and longitude based on the address provided. The documentation did not have complete solution or campaign setup details and that is the missing piece here for me. How in the example were they able to retrieve the long/lat variable values back and display to the user - I doubt if that example sends those longitude/latitude values via email response. 

SanfordWhiteman
Level 10 - Community Moderator

Re: How to return information from remote API back to the Marketo form


(Though when testing this in our sandbox environment, with no load, no concurrent users or any heavy activity, I can see the API returns within 1/1.5 seconds, the activity log of the webhook call shows values were returned and assigned as per the response mapping.)

That's an artificially pristine environment, and in reality no timing guarantees will ever be possible.

 

In addition to the latency of processing Filled Out Form, only 20 webhook connections can be opened at a time. And the cookie association with the inserted/merged lead — also necessary to see updated values — is yet another process that isn't guaranteed to happen immediately. (Quickly, but not immediately, and there's a world of difference.)

 


I also setup another trigger campaign to respond to "webhook is called" and in the flow wait for 1 minute followed by change data value to assign the values to variables. Still does not work.

I don't understand why you would add an additional Wait step? Call Webhook already changes the values per the Response Mapping.

 


Could you please elaborate on "The closest you could come is polling the follow-up page for, say, 30 seconds to look for an update." ? How would one implement this?

On the form page, in the onSuccess, you peek at the contents of the follow-up page, fetched over Ajax. You can reload it every 250ms for 30s, for example (though I usually keep it to 10s). When it contains matching data, then and only then do you redirect to the full Thank You URL.

 

Doesn't involve another form nor form post.

 


On a side note: I think I saw in Marketo documentation, webhook example related to Google's Geo API which returns latitude and longitude based on the address provided. The documentation did not have complete solution or campaign setup details and that is the missing piece here for me. How in the example were they able to retrieve the long/lat variable values back and display to the user - I doubt if that example sends those longitude/latitude values via email response. 

You can't fetch and display information like that in real time with Call Webhook. It's not possible. You could update fields, and after a certain period of time the {{lead.tokens}} would be populated and you could output them on an LP.