Lead Generation followed by Campaign Triggering via REST API

Anonymous
Not applicable

Lead Generation followed by Campaign Triggering via REST API

Hello,

    We are using Marketo REST API to (a) CREATE/UPDATE/GET leads, and (2) TRIGGER campaigns. The orchestration workflow is somewhat as follows:

    <1> Based on certain inputs, check whether lead exists, if it does, update certain attributes and trigger a campaign for the same lead id.

    <2> If the lead does not exist, create the lead with all available attributes and trigger a campaign for the same lead id.

    What we are observing is that, when the lead already exists, triggering of campaign is always successful.

    However, when the lead gets successfully created first, and the same lead id is passed as the input to 'POST .../campaigns/{campaignId}/trigger.json', sometimes we receive an error as 'LeadId {} not found'. From the call flow perspective, these are sequential calls that are executed when the prior succeeds.

    Could it be a timing issue? In other words, server has received 'Create Lead' and 'Trigger Campaign' request asynchronously, but 'campaign triggering' gets initiated before server has finished any house-keeping related to 'lead creation'.

    If the same lead is passed again immediately after the previous iteration through the same orchestration workflow, it goes through condition <1> and succeeds.

    Has anyone encountered similar situation? Any advise/feedback on some kind of work-around - maybe a time delay or try logic - would be helpful.

    One of the thoughts/approaches was to introduce a 'wait' in the campaign flow as a starting step, but we are not sure if there would be any other downfalls from the performance characteristics.

Appreciate your feedback and suggestions.

Thanks.

Tags (1)
3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Lead Generation followed by Campaign Triggering via REST API

Yes, you have a race condition. Instead of triggering the campaign using the API, trigger it from the Marketo side on lead creation.

I trust you are not running this process in response to individual end-user activity, or you're creating a DoS vulnerability.

Anonymous
Not applicable

Re: Lead Generation followed by Campaign Triggering via REST API

Thanks a lot for quick answer and confirmation about race condition.

We did have 'Lead Generation' action to trigger a campaign based on some trigger and filter conditions, to begin with. But we had to modify that due to some business requirements.

As mentioned earlier, we have modified the campaign flow to introduce a delay as the first step, when the 'Campaign is Requested' via REST API. Wondering if there are any other ways to address this situation.

Appreciate your feedback and suggestions

Thanks

SanfordWhiteman
Level 10 - Community Moderator

Re: Lead Generation followed by Campaign Triggering via REST API

But you can't fix race conditions with a delay: this is a fundamental reality of programming.  (The sole exception is when you have a guarantee that data is periodically flushed, so if you wait longer than that your data will be committed.)

In order to synchronize the data commit with your outside process, you can fire a webhook notification back into your service, which then calls Request Campaign.

I'm curious about what set of business requirements could lead you to this method instead of a standard, more scalable interaction with Marketo.