1

I've got some fulfillment code in dialogflow firebase where I ask for some user info, then I want to use that info to create a salesforce lead. This code is just grabbing the params from the agent:

function create_sf_lead(agent) {
  // assume full name is space separate non null string
  let human_name_arr = agent.parameters.human_name.split(' ');
  // if more than one name separate into last and first name
  if (human_name_arr.length > 1) {
    var last_name = human_name_arr.pop();
    var first_name = human_name_arr.join(' ');
  // otherwise assume first name only
  } else {
    var first_name = human_name_arr.pop();
  }


  let email = agent.parameters.email;
  let company = agent.parameters.company;
  let company_role = agent.parameters.company_role;
  let city = agent.parameters.city;
  let state = agent.parameters.state;

  //send JSON lead info to salesforce.....
  • is it standard web2Lead? – Pranay Jaiswal Nov 16 '18 at 16:45
  • Yeah I have webtolead setup, wasn't sure if that was what I should use or something else. – Nick Ellis Nov 16 '18 at 16:53
1

This is something I did recently using Angular, so I can answer this.

  1. Download Web2LeadForm: It would look something like this.

    <form action="https://test.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">
    
    <input type=hidden name="oid" value="00DPOQ00008ajh">
    <input type=hidden name="retURL" value="http://google.com">
    
    
    
    <label for="first_name">First Name</label><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
    
    <label for="last_name">Last Name</label><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>
    
    <label for="email">Email</label><input  id="email" maxlength="80" name="email" size="20" type="text" /><br>
    
    <label for="company">Company</label><input  id="company" maxlength="40" name="company" size="20" type="text" /><br>
    
    <label for="city">City</label><input  id="city" maxlength="40" name="city" size="20" type="text" /><br>
    
    <label for="state">State/Province</label><input  id="state" maxlength="20" name="state" size="20" type="text" /><br>
    
    <input type="submit" name="submit">
    
    </form>
    
    1. Change the action attribute of form to a URL generated from http://postb.in
    <form action="http://postb.in/ZLeviPDb" method="POST">
  1. Save the form as HTML document and open it in browser. Fill form and press submit.

  2. Check the postbin url to see what data was send in POST call, It would look something like

enter image description here

This is the POST request body you need to send from your JS code. Create an XMLHttpRequest and do a post call...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.