整合 salesforce 和 backendless

Integrate salesforce and backendless

我希望注册表单数据转到 Salesforce 潜在客户 table。

我有一个 WordPress 网站,我在其中使用 php 代码制作了一个注册表单,每当用户注册时,表单数据都会发送给 Backendless 用户 table,为此我有使用了 REST API 和 cURL。 所以现在我希望将相同的数据也发送给 Salesforce Lead table。 我还没有找到解决此问题的任何 REST API 解决方案,我需要 REST API 或 cURL 的代码或可以完成我的工作并将用户数据推送到 Salesforce 的插件。
我可以附上 backendless 的 WordPress 代码以供参考

<?php

if(isset($_POST['Submit'])) 
    {

    //extract data from the post
    //set POST variabless
    $fname = $_POST['fname'];
    $email = $_POST['email'];
    $password = $_POST['password'];

    //retrieve the data from the backendless table and check if the email is present in it.
    $service_url1 = 'https://api.backendless.com/{APP-KEY}/{REST-API}/data/Users';
    $curl1 = curl_init($service_url1);
    curl_setopt($curl1, CURLOPT_RETURNTRANSFER, true);
    $curl_response1 = curl_exec($curl1);

    if ($curl_response1 === false) {
        $info1 = curl_getinfo($curl1);
        curl_close($curl1);
        die('error occured during curl exec. Additioanl info: ' . var_export($info1));
    }
    curl_close($curl1);
    //getting the array which is stored in $curl_response1, putting it in decoded and puiling out only the email field and arranging it properly.
    $decoded = json_decode($curl_response1);
    $res1 = array_column($decoded, 'email');
    $res2 = implode("', '", $res1);
    //checking if the new user email is present in the array or not.
    if (in_array($email, $res1)) 
        {
            echo"<div style='text-align:center'>You have already registered before.</div>"; 

        }       

    else
        {
            //since its not present in the backendless table we will now add it to the backendless table by POST.
            $ch = curl_init('https://api.backendless.com/{APP-KEY}/{REST-API}/data/Users');
            $data = array("fname" => $fname, "email" => $email, "password" => $password);

            $data_string = json_encode($data);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json',
                'Content-Length: ' . strlen($data_string))
            );
            curl_setopt($ch, CURLOPT_TIMEOUT, 5);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
            //execute post
            $result = curl_exec($ch);
            //close connection
            curl_close($ch);

            echo"<div style='text-align:center'>Thank you for signing up with us ".$fname.".<br> </div>";
            echo"<div style='text-align:center'>We will be sending you an email shortly.</div>";

        }

}

else
{

?>
<html>
<head>
<style> 
input[type='text'], input[type='email'], input[type='password'] { border : 0.5px solid gray; margin-bottom: 5px; }
.signup-submit {margin-top:20px;}
input[type='password'] { 
    padding-top: 8px;
    padding-bottom: 8px;
}
</style>
</head>
<body style="text-align:left;">

<div>

    <p align="center"> Please complete the following form to register as a user </p>

    <form method="post" id="signup">

        <table>
            <tr>
                <div class="col-sm-12 col-xs-12">
                    <span class="wpcf7-form-control-wrap fname">
                        <td>
                            <label>Enter Name * : </label>
                        </td>                   
                        <td>
                            <input type="text" name="fname" value="" size="15" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required wpcf7-validates-as-name required " aria-required="true" aria-invalid="false" required />
                        </td>
                    </span>
                </div>  
            </tr>


            <tr>
                <div class="col-sm-12 col-xs-12">
                    <span class="wpcf7-form-control-wrap email">
                        <td>
                            <label>Enter Email * : </label>
                        </td>                   
                        <td>
                            <input type="email" name="email" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required wpcf7-validates-as-email required email" aria-required="true" aria-invalid="false" required />
                        </td>
                    </span>
                </div>  
            </tr>

                <tr>
                <div class="col-sm-12 col-xs-12">
                    <span class="wpcf7-form-control-wrap password">
                        <td>
                            <label>Enter Password * : </label>
                        </td>                   
                        <td>
                            <input type="password" name="password"  value="" id="pwinput"  minlength="8" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" aria-required="true" aria-invalid="false" autocomplete="new-password" required />

                            <input type="checkbox" onclick="myFunction()"><span class="checkboxtext">Show Password</span>
                        </td>
                        <script>
                            function myFunction() 
                            {
                                var x = document.getElementById("pwinput");
                                if (x.type === "password") 
                                    {
                                        x.type = "text";
                                    } 
                                else 
                                    {
                                        x.type = "password";
                                    }
                            }
                        </script>
                    </span>
                </div>  
            </tr>


            <tr>
                <div class="col-sm-12 col-xs-12">

                        <td>
                            <input type="submit" value="Submit" name="Submit" class="wpcf7-form-control wpcf7-submit signup-submit center Submit">
                        </td>
                </div>  
            </tr>
        </table>  
    </form>
</div>
</body>
</html>

<?php
 }
?>

基本

Salesforce 提供 Web-to-Lead 和 Web-to-Case 解决方案。它们非常易于使用(您无需先登录 SF),您通过 SF 单击以生成 HTTP POST 表单。然后查看它,您可以轻松地弄清楚如何发出 POST 请求。

它们也很原始,它们通过将您的唯一 SF 组织 ID 传递给通用的 url 来工作,后者将分派请求 - 所以这是您肯定想隐藏的东西 server-side,也许使用 CAPTCHA 进行保护...一旦有人知道您的 SF 组织 ID,他们就可以轻松地向您发送数以千计的假线索。阅读与 Web-to-Lead、限制相关的帮助,并确定它是否正确。

SF 会从中生成一个 HTML 表格

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

<input type=hidden name="oid" value="00D7000000{hidden}">
<input type=hidden name="retURL" value="https://whosebug.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>
...

所以现在您有 URL 和 POST 的参数。拍打 Content-Type:application/x-www-form-urlencoded header 作为衡量标准,您就可以开始了。也许将组织 ID 保留在某些配置中,以便您可以轻松地在测试和生产 SF 实例之间切换。

高级

如果您需要更高级的东西(不仅加载 Lead,还加载其他表,可能是附件,可能检查是否存在相同的电子邮件并应首先更新...)- 您需要适当的 API 访问权限、SOAP 或 REST。这意味着两次 POST 调用,一次用于获取 session ID,一次用于实际保存。您可以 hand-craft 全部或使用 SF PHP 库之一,例如 https://developer.salesforce.com/index.php?title=Getting_Started_with_the_Force.com_Toolkit_for_PHP&oldid=51397. If you hand-craft - sample login message is here https://whosebug.com/a/56034159/313628 或转到 REST API 文档。

进入后(您也可以使用 https://workbench.developerforce.com/login.php -> REST explorer or https://developer.salesforce.com/docs/api-explorer/sobject/Lead

嗨,我发布了对我有用的解决方案,以帮助将来的人!

<?php

if(isset($_POST['Submit'])) 
    {

    //extract data from the post
    //set POST variabless
    $fname = $_POST['fname'];
    $email = $_POST['email'];
    $password = $_POST['password'];

    //retrieve the data from the backendless table and check if the email is present in it.
    $service_url1 = 'https://api.backendless.com/<App-id>/<Rest-api-key>/data/Users';
    $curl1 = curl_init($service_url1);
    curl_setopt($curl1, CURLOPT_RETURNTRANSFER, true);
    $curl_response1 = curl_exec($curl1);

    if ($curl_response1 === false) {
        $info1 = curl_getinfo($curl1);
        curl_close($curl1);
        die('error occured during curl exec. Additioanl info: ' . var_export($info1));
    }
    curl_close($curl1);
    //getting the array which is stored in $curl_response1, putting it in decoded and pulling out only the email field and arranging it properly.
    $decoded = json_decode($curl_response1);
    $res1 = array_column($decoded, 'email');
    $res2 = implode("', '", $res1);

    //checking if the new user email is present in the array or not.
    if (in_array($email, $res1)) 
        {
            echo"<div style='text-align:center'>You have already registered before.</div>"; 
            echo '<th><strong><u><center><a target="_blank" href="javascript:window.close();">Click here to return.</a></center></u></strong></th>';        
        }       

    else
        {
            //since its not present in the backendless table we will now add it to the backendless table by POST.
            $ch = curl_init('https://api.backendless.com/<App-id>/<Rest-api-key>/data/Users');
            $data = array("fname" => $fname, "email" => $email, "password" => $password);

            $data_string = json_encode($data);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json',
                'Content-Length: ' . strlen($data_string))
            );
            curl_setopt($ch, CURLOPT_TIMEOUT, 5);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
            //execute post
            $result = curl_exec($ch);
            //close connection
            curl_close($ch);

            echo"<div style='text-align:center'>Thank you for signing up with us ".$fname.".<br> </div>";
            echo"<div style='text-align:center'>We will be sending you an email shortly.</div>";
            echo '<th><strong><u><center><a style="color:#2c666d" target="_blank" href="javascript:window.close();">Click here to return.</a></center></u></th>';
        }

}

else
{

?>
<html>
<head>
<style> 
input[type='text'], input[type='email'], input[type='password'] { border : 0.5px solid gray; margin-bottom: 5px; }
.signup-submit {margin-top:20px;}
input[type='password'] { 
    padding-top: 8px;
    padding-bottom: 8px;
}
</style>
</head>
<body style="text-align:left;">

<div>

    <p align="center"> Please complete the following form to register as a user </p>

    <form method="post" id="signup">

        <table>
            <tr>
                <div>
                    <span class="fname">
                        <td>
                            <label>Enter Name * : </label>
                        </td>                   
                        <td>
                            <input type="text" name="fname" value="" size="15" required />
                        </td>
                    </span>
                </div>  
            </tr>


            <tr>
                <div>
                    <span class="email">
                        <td>
                            <label>Enter Email * : </label>
                        </td>                   
                        <td>
                            <input type="email" name="email" value="" size="40" required />
                        </td>
                    </span>
                </div>  
            </tr>

                <tr>
                <div>
                    <span class="password">
                        <td>
                            <label>Enter Password * : </label>
                        </td>                   
                        <td>
                            <input type="password" name="password"  value="" minlength="8" required />

                            <input type="checkbox" onclick="myFunction()"><span class="checkboxtext">Show Password</span>
                        </td>
                    </span>
                </div>  
            </tr>

            <tr>
                <div>

                        <td>
                            <input type="submit" value="Submit" name="Submit" class="Submit">
                        </td>
                </div>  
            </tr>
        </table>  
    </form>
</div>
</body>
</html>

<?php
 }
?>