tsturzl tsturzl - 1 month ago 16
HTTP Question

Cannot get node-request to post to salesforce web-to-lead

We've been requested by a client of ours to integrate with their salesforce. However, they refuse to give us an oAuth token. What they did provide was a Web-to-Lead

oid
. Essentially Web-to-Lead is a simple web form that's generated with an
oid
to relate it to your salesforce account. However, I'm having trouble getting anything else to POST to salesforce using curl, postman, or node.js and request module.

I set up a sand box to test this, since they complained that they weren't getting applications. I'm noticing also that theses applications aren't appearing, however if I use the actual form that salesforce generated for me, everything seems to work fine.

Basically me code resembles this:

var request=require("request");

var form={
"oid":"xxxx",
"first_name":"TEST",
"last_name":"TEST",
"email":"xxxx@gmail.com",
"street":"xxx Some Road",
"city":"somewhere",
"state":"Wisconsin",
"zip":"54944",
"00No00000045JeV":"Internet",
"00No00000045Jef":"American Driver Network",
"00No00000045Jek":"Class A",
"00No00000045Jep":"50",
"00No00000045Jf4":"0",
"00No00000045JfE":"0",
"00No00000045JfJ":"0",
"retURL":"http://"
};

var options={
url:"",
form:form
};

request.post(options,function(err,resp,body){
//salesforce gives no useful response so do nothing
});


Request module should be setting my header appropriately.

The salesforce form:

<!-- ---------------------------------------------------------------------- -->
<!-- NOTE: Please add the following <META> element to your page <HEAD>. -->
<!-- If necessary, please modify the charset parameter to specify the -->
<!-- character set of your HTML page. -->
<!-- ---------------------------------------------------------------------- -->

<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">

<!-- ---------------------------------------------------------------------- -->
<!-- NOTE: Please add the following <FORM> element to your page. -->
<!-- ---------------------------------------------------------------------- -->

<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">

<input type=hidden name="oid" value="00Do0000000KlmA">
<input type=hidden name="retURL" value="http://">

<!-- ---------------------------------------------------------------------- -->
<!-- NOTE: These fields are optional debugging elements. Please uncomment -->
<!-- these lines if you wish to test in debug mode. -->
<!-- <input type="hidden" name="debug" value=1> -->
<!-- <input type="hidden" name="debugEmail" -->
<!-- value="travissturzl@gmail.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="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>

<label for="phone">Phone</label><input id="phone" maxlength="40" name="phone" size="20" type="text" /><br>

<label for="street">Address</label><textarea name="street"></textarea><br>

<label for="zip">Zip</label><input id="zip" maxlength="20" name="zip" size="20" type="text" /><br>

Media Type:<input id="00No00000045JeV" maxlength="50" name="00No00000045JeV" size="20" type="text" /><br>

Media Source:<input id="00No00000045Jef" maxlength="50" name="00No00000045Jef" size="20" type="text" /><br>

License Type:<input id="00No00000045Jek" maxlength="50" name="00No00000045Jek" size="20" type="text" /><br>

Months of Experience:<input id="00No00000045Jep" name="00No00000045Jep" size="20" type="text" /><br>

Accidents:<input id="00No00000045Jf4" name="00No00000045Jf4" size="20" type="text" /><br>

Moving Violations:<input id="00No00000045JfE" name="00No00000045JfE" size="20" type="text" /><br>

DUI:<input id="00No00000045JfJ" name="00No00000045JfJ" size="20" type="text" /><br>

<input type="submit" name="submit">

</form>


I have no idea what I'm doing wrong. I've never had an issue like this. Am I missing something?

Answer

I think you are missing the url in your options:

var options={
    url:"https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8",
    form:form
};

You are just making no request without providing the url to post to!