SOLVED

How do I send a confirmation email with a unique code?

Go to solution
SanfordWhiteman
Level 10 - Community Moderator

Re: How do I send a confirmation email with a unique code?

OK, I’m back with more answers! Had a call.

 


3) In your sample webhook code (1st one) , you have two lines at the top
 var fileOfCodes = "https://pages.example.com/rs/111-222-333/images/sample_codes.txt";
 var counter = "/distributed_codes/{{Program.Id}}/v1";

           fileOfCodes is a variable holding the text file, we import that file into marketo and adjust the https://pages.example.... with the actual path where we uploaded the text file

counter is a variable holding the count. What does or how does the "/distributed_codes/{{Program.Id}}/v1" keep track of the  count?

Yes, fileOfCodes points to the Design Studio asset.

 

The code is using FBCounter (actually a simple key-value database, etcd, under the hood) and its method called autoAdd()autoAdd() just adds an automatically-generated unique entry (like a GUID) under the counter path (/codes/12345/v1/...) every time you call it. So it doesn’t have to know what it’s counting — it just counts and tells you how many entries there are!

SanfordWhiteman
Level 10 - Community Moderator

Re: How do I send a confirmation email with a unique code?


When creating the webhook, where do we put the sample code? 
 var fileOfCodes = "https://pages.example.com/rs/111-222-333/images/sample_codes.txt";

   var counter = "/distributed_codes/{{Program.Id}}/v1";

   FBHttp.fetch(fileOfCodes)
  .then( resp => resp.text() )
  .then( respT => respT.split(/\r?\n/) )
  .then ( codes =>
      FBCounter.count(counter)
      .catch( count => 0 )
      .then( count =>
             count < codes.length
             ? FBCounter.autoAdd(counter).then( resp => success(codes[count]))
                  : failure("All outta codes!")

               )
             ) 
.catch(failure)

That goes in the webhook Payload textbox.

 

But I think there’s one piece you might not be clear on: you need a FlowBoost API key to make this call. It’s free (Community key is 100,000 calls/month which certainly seems beyond your usage) but you need to fill out the form!