How to return information from remote API back to the Marketo form | Community
Skip to main content
Level 2
March 17, 2021
Question

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

  • March 17, 2021
  • 1 reply
  • 2771 views

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.

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

SanfordWhiteman
Level 10
March 17, 2021

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.)

desijadooAuthor
Level 2
March 17, 2021

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:

 

Campaign Flow step:

 

 My Webpage Form script:

values.rmsWHDocURL and values.rmsWHDocTitle remain empty. 

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

SanfordWhiteman
Level 10
March 17, 2021

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.