You need to sign in to do that
Don't have an account?
landyman
Perl API problems
Hello,
We've been using the Perl API since October for a 'web to lead' type application. Since the new year, we've been experiencing a lot of problems with the API not sending the data to Salesforce.
The code has an error check in it where we check for "success" in the XML, but that code never executes. When we look at our logs, we see that there is no "success" variable to check. Almost like we aren't receiving a response at all.
Has anyone else experienced these intermittent problems? If so, have you fixed them and how?
I've posted our code here in case there is something messed up with it. Thanks in advance!
We've been using the Perl API since October for a 'web to lead' type application. Since the new year, we've been experiencing a lot of problems with the API not sending the data to Salesforce.
The code has an error check in it where we check for "success" in the XML, but that code never executes. When we look at our logs, we see that there is no "success" variable to check. Almost like we aren't receiving a response at all.
Has anyone else experienced these intermittent problems? If so, have you fixed them and how?
I've posted our code here in case there is something messed up with it. Thanks in advance!
Code:
#START Salesforce use WWW::Salesforce::Simple; # Authenticate with the Salesforce API based on command line parameters. my $sforce = WWW::Salesforce::Simple->new( 'username' => 'xxxxxxxx@xxxxxxxxx.xxx', 'password' => 'xxxxxx' ); #create lead my %lead; $lead{'type'} = 'Lead'; my ($first, $last) = split(/ /, $FORM{'contact'}, 2); unless ($last) { $last = $first; $first = ""; } $lead{'FirstName'} = $first if $first; $lead{'LastName'} = $last if $last; $lead{'Company'} = $FORM{'company'}; $lead{'Street'} = $FORM{'address1'} . " " . $FORM{'address2'}; $lead{'City'} = $FORM{'city'}; $lead{'State'} = $FORM{'state'}; $lead{'PostalCode'} = $FORM{'zip'}; $lead{'Phone'} = $FORM{'phone'}; $lead{'Website'} = $FORM{'url'}; $lead{'Email'} = $FORM{'email'}; if (length($FORM{'other'}) > 0) { $lead{'LeadSource'} = $FORM{'source'} . " -- " . $FORM{'other'}; } else { $lead{'LeadSource'} = $FORM{'source'}; } $lead{'Sales_Region__c'} = $FORM{'salesregion'}; $lead{'Found_us_from__c'} = $fus; $lead{'Sales_Description__c'} = $FORM{'descript'}; $lead{'URL_Title__c'} = $FORM{'title'}; $lead{'Initial_Keywords__c'} = $FORM{'keywords'}; $lead{'Google_Results__c'} = "PageRank:$rf[3]\n Inbound Links: $rf[4]\n Site Pages Spidered: $rf[5]\n\n"; #submit lead to salesforce my $res = $sforce->create(%lead); if ($res->result->{"success"} == "false") { print $res->result->{errors}->{message} . '\n'; } # END Salesforce
if ($res->result->{"success"} == "false") {
...should be...
if ($res->result->{"success"} eq "false") {
That might help you get better debugging info. You might also have a problem with stuff like:
$lead{'Company'} = $FORM{'company'};
If company has an ampersand or other special char in it, the SOAP call is going to fail. You should be doing something like this:
$lead{'Company'} = CGI::escapeHTML($FORM{'company'});
I too find the API intermittently fails. Our solution is store all data locally in a mysql database and then run a periodic cron job that sends the data into Salesforce. If it goes into SF successfully then we update a flag in the local database -- otherwise we know we need to try it again.
I also read on another post that I should type-cast custom variables to make sure that they are stored the way they should be. This also seemed to help:
I am thinking about implementing the same kind of thing you have where we write to a 'middle-man' place and then batch uploading it into Salesforce... or, I just might do it in a different language (we use the PHP API as well and have had no problems with it) if the PERL API does this pretty frequently.