使用 Web 服务将报价导入 vtiger crm

2024-02-04

我需要将报价导入到vtiger。 我发现可以使用 vtiger Web 服务 API 来完成

我找到了参考手册:https://wiki.vtiger.com/archives/index.php/vtiger510:Webservice_reference_manual https://wiki.vtiger.com/archives/index.php/vtiger510:Webservice_reference_manual

但我找不到任何示例 PHP 脚本,也找不到我需要传递到的数据字段webservice.php.

请帮忙,我需要一些指导。


我做了类似的事情,我有一个快速且(相当)肮脏但有效的解决方案:

<?php

function createOffer($account_id,$subject,$offerlanguage, $totalamount,$date_submission,$date_decision,$date_start,$assigned_user_id,$quotestage,$winningchance,$description,$productarray){

        global $adb;

        $endpointUrl = "[your URL]/webservice.php";
        $userName="admin";
        $userAccessKey = '[your accesskey]';

        $httpc = new HTTP_CLIENT();

        //getchallenge request must be a GET request.
        $httpc->GET($endpointUrl."?operation=getchallenge&username=".$userName);

        $response = $httpc->currentResponse();
        //decode the json encode response from the server.
        $jsonResponse = Zend_JSON::decode($response['body']);

        //check for whether the requested operation was successful or not.
        if($jsonResponse['success']==false)
            //handle the failure case.
            die('getchallenge failed:'.$jsonResponse['error']['errorMsg']);

        //operation was successful get the token from the reponse.
        $challengeToken = $jsonResponse['result']['token'];
        //create md5 string concatenating user accesskey from my preference page
        //and the challenge token obtained from get challenge result.
        $generatedKey = md5($challengeToken.$userAccessKey);

        //getchallenge request must be a GET request.
        $httpc->post("$endpointUrl",
                        array('operation'=>'login', 'username'=>$userName, 'accessKey'=>$generatedKey), true);
        $response = $httpc->currentResponse();

        //decode the json encode response from the server.
        $jsonResponse = Zend_JSON::decode($response['body']);

        //operation was successful get the token from the reponse.
        if($jsonResponse['success']==false)
            //handle the failure case.
            die('login failed:'.$jsonResponse['error']['errorMsg']);

        //login successful extract sessionId and userId from LoginResult to it can used for further calls.
        $sessionId = $jsonResponse['result']['sessionName'];
        $userId = $jsonResponse['result']['userId'];

        $currency_id=1;
        $params =  array('description'=>$description,'subject'=>$subject,'quotestage'=>$quotestage,'assigned_user_id'=>'2x'.$assigned_user_id,'account_id'=>'3x'.$account_id,'cf_682'=>$offerlanguage,'currency_id'=>'21x'.$currency_id,'taxtype'=>'group','cf_683'=>$date_submission,'cf_684'=>$date_decision,'cf_685'=>$date_start,'cf_766'=>$winningchance);

        $urlArgs = "?&total=".$totalamount;
        //encode the object in JSON format to communicate with the server.
        $objectJson = Zend_JSON::encode($params);
        //name of the module for which the entry has to be created.
        $moduleName = 'Quotes';
        //sessionId is obtained from loginResult.
        $params = array("sessionName"=>$sessionId, "operation"=>'create', "element"=>$objectJson, "elementType"=>$moduleName);
        //Create must be POST Request.
        $httpc->post($endpointUrl.$urlArgs, $params, true);
        $response = $httpc->currentResponse();
        //decode the json encode response from the server.
        $jsonResponse = Zend_JSON::decode($response['body']);

        $savedObject = $jsonResponse['result'];
        $id = $savedObject['id'];   

        $id=str_replace("13x", "", $id);

        echo $id." offer: ".$subject." created for amount ".$totalamount." for customer: ".$account_id." assigned to: ".$assigned_user_id;

        return $id;

    }

正如您所看到的,还有一些自定义字段,因此您可以看到我是如何处理这些字段的。

你可以这样调用这个函数:

createOffer($account_id, $subject, $offerlanguage, $totalamount, $date_submission, $date_decision, $date_start, $assigned_user_id, $quotestage, $winningchance, $description, $productarray)

然后您还需要添加产品,我发现通过单独的功能最简单,因为每个报价可以有更多产品......

<?php

function createProducts($productarray,$id) {
    $counter = 1;
    foreach ($productarray as $prod) {
        $query ="insert into vtiger_inventoryproductrel(id, productid, sequence_no, quantity, listprice) values(?,?,?,?,?)";
        $qparams = array($id,$prod['prod'],$counter,$prod['pcs'],$prod['price']);
        $productadded=$adb->pquery($query,$qparams);
        $counter=$counter+1;
    }
}

像这样使用它:

$prodlist = array();

array_push($prodlist,array('prod'=>"prod1",'pcs'=>2,'price'=>1000));
array_push($prodlist,array('prod'=>"prod2",'pcs'=>2,'price'=>100));

createProducts($prodlist,10);

所以我的逻辑是这样的:

  • 您使用 createOffer 函数创建报价。它返回新创建的报价的 ID
  • 然后构建产品数组(我这里只有非常基本的数据)并通过引用报价 ID 来添加它

也许不是最漂亮的解决方案,但确实有效。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Web 服务将报价导入 vtiger crm 的相关文章

  • 按通用值对值进行分组:userid 和 ipaddress

    我正在解决数据库中的一个问题 我正在尝试查找使用多个帐户的用户 我有一个用户 ID 和使用的 IP 地址的列表 如下所示 用户 ID IP 地址 1 IP 地址 13 2 IP 地址 23 1 IP 地址 12 4 IP地址56 9 IP
  • PHP - Filter_var 替代方案?

    我构建了一个 php 脚本来输出以表单形式发布的数据 但遇到了问题 网站将运行的服务器运行 PHP 5 1 6 此版本的 PHP 不支持 filter var 我需要知道短期内的替代方案 最好是昨天 但在 Google 或 Stack Ov
  • 如何在 Laravel 查询中使用多个 OR,AND 条件

    我需要 Laravel 查询帮助 我的自定义查询 返回正确结果 Select FROM events WHERE status 0 AND type public or type private 如何写这个查询Laravel Event w
  • PHP 或 WAMP 不确定是什么

    我已经安装了 WAMP 服务器 2 0 PHP 5 4 3 安装WAMP后我已经重新启动了所有服务并且可以打开 phpinfo 显示良好 phpmyadmin 它也显示得很好 我可以使用数据库 然而 当在 Chrome 中运行简单的 php
  • 如何让WebClient(Web服务客户端)自动使用默认代理服务器?

    我正在从 WinForms 应用程序调用 Web 服务 当不使用代理服务器时 一切工作正常 但是当使用代理时 应用程序会崩溃 因为它收到的不是它期望的 SOAP 请求的 XML 响应 而是一个 HTML 错误页面 显示 需要身份验证 看来你
  • 当sql连接中存在两个同名列时,如何从一个表列中获取值

    当我连接两个具有相同名称列的表时 我目前面临着尝试获取值的问题 例如 table1 date和table2 date 每个表中的日期不同 我将如何获取 日期 本例中的表1 我目前正在跑步 while row mysqliquery gt f
  • 使用 php 在多维数组中按键排序[重复]

    这个问题在这里已经有答案了 可能的重复 在 PHP 中对多维数组进行排序 https stackoverflow com questions 2059255 sorting multidimensional array in php 如何在
  • 如何使用 Twig 的属性函数访问嵌套对象属性

    我试图使用一个树枝变量来访问另一个树枝变量的属性 直到我找到 属性 函数为止 该变量才起作用 除了需要访问嵌套属性的情况外 效果很好 当包含属性的变量实际上是对象 属性时 它不起作用 例如 attribute object1 variabl
  • 如何在 PHP 中使用 cURL 发出同时包含 GET 和 POST 参数的请求?

    其他人已经问过如何从 perl java bash 等执行此操作 但我需要在 PHP 中执行此操作 并且我没有看到任何已提出的专门与 PHP 相关的问题 或包含 PHP 的答案 My code ch curl init url curl s
  • 限制自己超载外部 API 的速率

    我发现了很多信息和脚本示例 展示了如何对 API 用户进行速率限制 但我无法找到任何示例来说明在施加这些限制时如何对您自己的 API 请求进行速率限制 我总是用诸如以下的代码来限制我的脚本sleep or usleep命令 但感觉这是一种低
  • 为什么我的 if 语句没有按我预期的方式工作?

    我正在尝试实现以下目标 我向我的 SQL 数据库询问使用SELECT FROM subjects 这样做之后我要求使用数组mysqli fetch assoc 在那之前一切都很好 现在的问题是 当我尝试在每个循环中修改 genero 的值
  • 强制 Composer 下载 git repo 而不是 zip

    我对作曲家有一些问题 require php gt 5 3 2 kriswallsmith buzz 0 7 Repo https github com kriswallsmith Buzz tree v0 7 https github c
  • postgreSql 中特定时间后表更新

    我已经在 postgres 中创建了表 现在我想在特定时间 例如 1 小时 后更新一行 我看到很多问题 例如 https dba stackexchange com questions 56424 column auto updated a
  • 自动建议 php 的 ajax

    我有一个 html 表单 php 脚本和 jquery 我需要一个 ajax 代码来从我的 php 脚本中进行自动建议 以下是代码 表单 html
  • MVC 模式中的验证层

    验证模型将使用的数据的最佳位置在哪里 例如 考虑登记表 我们有一些来自注册表的数据 那么验证这些数据的最佳位置在哪里 我们应该通过 if 语句或特殊的验证器类来检查每个数据 这意味着大量的编码 所以我想了解在哪里可以做到这一点 在控制器中
  • WordPress 插件中的类自动加载器

    我想编写一个类自动加载器以在 WordPress 插件中使用 该插件将安装在多个站点上 我想尽量减少与其他插件发生冲突的机会 自动加载器将是这样的 function autoload name some code here 我的主要问题是
  • 如何在 Zend Framework 3 中注册自定义表单视图助手

    我正在将继承的 Zend Framework 2 应用程序迁移到 Zend Framework 3 并且在注册自定义表单视图助手时遇到了一些困难 这些助手在应用程序使用版本 2 时起作用 主要用于添加标签属性以实现可访问性 例如 这是一个自
  • php curl 使用 GET 发送变量 奇怪的结果

    我正在尝试调用远程站点上页面中的网址 决定使用curl 在远程站点上 url 变量显示为 REQUEST Array var1 gt val1 amp var2 gt val2 amp var3 gt val3 被调用的url是 http
  • 如何在laravel中注册后自动登录

    我在 laravel 中注册用户时遇到问题 user假设是包含所有数组元素的数组 同时自动登录以下代码结果false 数据库中保存的密码是hash make password user id this gt user model gt ad
  • 使用 php-ews(Exchange Web 服务)在特定日期后获取电子邮件

    在我的 PHP 脚本中 我需要弄清楚如何检索指定消息 ID 之后或特定日期之后的所有电子邮件 两者都可以 我只需要检索自上次抓取收件箱以来的新电子邮件 这个收件箱每天收到数千封电子邮件 而且我在 30 天内无法删除任何电子邮件 对于初始导入

随机推荐