【问题标题】:Integrate salesforce and backendless整合 salesforce 和 backendless
【发布时间】:2019-10-11 14:43:00
【问题描述】:

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

我有一个 WordPress 网站,我使用 php 代码制作了一个注册表单,每当用户注册时,表单数据都会转到 Backendless 用户表,为此我使用了 REST API 和 cURL。 所以现在我希望同样的数据也能进入 Salesforce Lead 表。 我还没有找到解决这个问题的任何 REST API 解决方案,我需要 REST API 或 cURL 的代码或可以完成我的工作并将用户数据推送到 Salesforce 的插件。
我可以附上一个带有 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
 }
?>

【问题讨论】:

    标签: php wordpress api salesforce backendless


    【解决方案1】:

    基本

    Salesforce 提供在线潜在客户和在线个案解决方案。它们非常易于使用(您无需先登录到 SF),您单击 SF 以生成 HTTP POST 表单。然后看看它,你可以很容易地弄清楚如何发出 POST 请求。

    它们也非常原始,它们通过将您唯一的 SF org id 传递给将发送请求的通用 url 来工作 - 所以这是您肯定想在服务器端隐藏的东西,也许用 CAPTCHA 保护......那一刻有人知道您的 SF org id,他们可以很容易地向您发送成千上万的虚假信息。阅读与在线潜在客户、限制相关的帮助并确定它是否正确。

    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://stackoverflow.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>
    ...
    

    现在您有了 POST 的 URL 和参数。拍打Content-Type:application/x-www-form-urlencoded 标头以防万一,您就可以开始了。也许将组织 ID 保留在某些配置中,以便您可以轻松地在测试和生产 SF 实例之间进行更改。

    高级

    如果您需要更高级的内容(不仅加载 Lead,还加载其他表格,可能是附件,可能检查是否存在相同的电子邮件并应首先更新...) - 您需要适当的 API 访问、SOAP 或 REST。这意味着两个 POST 调用,一个用于获取会话 ID,一个用于实际保存。您可以全部手工制作,也可以使用 SF PHP 库之一,例如 https://developer.salesforce.com/index.php?title=Getting_Started_with_the_Force.com_Toolkit_for_PHP&oldid=51397。如果您手工制作 - 示例登录消息在这里 https://stackoverflow.com/a/56034159/313628 或转到 REST API 文档。

    一旦你进入(你也可以使用https://workbench.developerforce.com/login.php -> REST explorer 或https://developer.salesforce.com/docs/api-explorer/sobject/Lead

    【讨论】:

      【解决方案2】:

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

      <?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
       }
      ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-11-10
        • 2016-11-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-29
        • 2014-01-09
        • 1970-01-01
        相关资源
        最近更新 更多