使用 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 的相关文章

  • 如何仅在 PHP 中使用 str_replace() 删除文本一定次数?

    我试图从字符串中删除单词 John 一定次数 我在 php 手册上读到 str replace 除了第四个参数 count 所以我想可以用来指定应该删除多少个搜索实例 但事实似乎并非如此 因为以下情况 string Hello John h
  • 如何在iPhone上读入并解析XML文件?

    我有一个返回 XML 文件的 Web 服务器 可以说http www foo bar foo php wantXML 1 http www foo bar foo php wantXML 1 我如何从服务器获取该文件 然后解析它以访问数据
  • 包含 WordPress 之外的 WordPress 内容

    我正在寻找构建 WordPress 网站的移动版本 并将其大部分内置于静态文件中 但我试图从运行移动网站的外部 PHP 文件内部访问 WordPress 内容 如何在不手动编写 SQL 查询的情况下访问循环或数据库 Edit 为了澄清一下
  • 在 WordPress 中挂钩 AJAX

    我一直在深入研究 Javascript 和 AJAX 的世界 我非常接近 但由于某种原因 我认为我没有正确地连接到 wordpress ajax 函数 我已经仔细阅读了文档和这个 认为 99 都在那里 这个应用程序的作用是有一个项目列表 每
  • 雄辩的致命错误:参数传递的实例不正确

    我正在使用 Slim 和 Eloquent 在 PHP 中构建端点系统 如上所述here http www slimframework com news slim and laravel eloquent orm 在我的本地开发中运行它时
  • nginx + php-fpm = 找不到文件

    当我尝试访问时info php我得到一个File not found error 我尝试了一些教程但无济于事 配置 默认 server listen 80 listen 80 default ipv6only on server name
  • 使用 Stripe 创建订阅后如何获取费用 ID?

    我在用Stripe作为支付网关 现在有一个大问题困扰着我 我使用下面的代码来创建订阅
  • 如何使用Google API PHP SDK获取用户信息

    我正在尝试为拥有 Google 帐户的用户添加登录选项到我的网站 我已经能够实现这个 Facebook 但在使用 Google 获取用户帐户信息时遇到问题 我正在使用位于此处的 Google PHP SDK https github com
  • 避免刷新时上传图片

    我正在使用最简单的图像上传形式 我非常希望保持这种方式 只需要一些 php 代码看起来像这样
  • 美化html输出

    我想知道是否有类或类似的东西可以包含在我的 PHP 页面中以美化 HTML 输出 例如在标签后添加新行并正确缩进 以便我的源代码不仅仅是一行 我知道对于浏览器来说这并不重要 但我希望这样做 我听说过http www php net manu
  • 无法访问扩展 Symfony\Bundle\FrameworkBundle\Controller\Controller 的控制器中的 Symfony2 容器

    原始问题 我已经阅读了 book http symfony com doc current book service container html 关于服务容器 我仍然感到困惑 因为几乎每次我尝试使用时 事情似乎都随机不起作用 this g
  • 将字符串作为 PChar 从 CSharp 传递到 Delphi DLL

    我正在尝试将字符串从 C 传递到 Delphi 构建的 DLL Delphi DLL 需要 PChar 这是Delphi导出 procedure DLL Message Location PChar AIntValue integer st
  • 我可以使用 vim “star” 搜索来搜索 PHP 类成员和方法吗?

    vim 星号 星号搜索 help star 是一个很棒的功能 它可以让您找到光标所在单词的下一个出现位置 不幸的是 它将美元前缀视为字符串的一部分 因此如果我在类名中的 SearchTerm 上方按 它会在注释中找到 SearchTerm
  • 使用 Hudson 将构建与部署分开

    我们已经开始使用Hudson 目前的工作流程是 本地签出 gt 代码 gt 运行测试 gt 更新 gt 运行测试 gt 提交 Hudson 并不进行轮询 而是只是坐在那里 直到我们实例化构建 然后它 本地结帐 gt 运行 Phing 脚本
  • 返回导航缓存 - IE

    当我在 IE 11 上运行 Web 应用程序时 收到如下警告消息 DOM7011 此页面上的代码禁用了后退和前进缓存 为了 更多信息 请参阅 http go microsoft com fwlink LinkID 291337 http g
  • PHP 多个 Curl 请求

    我目前经常使用 PHP 的 Curl 每次获取100页左右的结果需要花费很多时间 对于每个请求 我都使用这样的代码 ch curl init get source curl close ch 我有什么选择可以加快速度 我应该如何使用mult
  • 处理照片上传的最佳方式是什么?

    我正在为一个家庭成员的婚礼制作一个网站 他们要求的一个功能是一个照片部分 所有客人都可以在婚礼结束后前往并上传他们的照片 我说这是一个很棒的想法 然后我就去实现它 那么只有一个问题 物流 上传速度很慢 现代相机拍摄的照片很大 2 5 兆 我
  • 谷歌图片搜索API

    我有一个网站 用户可以在其中提交图片 我想用这些图片自动在 Google 上进行搜索 以尽量减少图片被从其他网站盗用的可能性 我知道 Firefox 扩展 但这需要我右键单击每张图片并等待结果出现 我想自动化这个 我一直在寻找 API 但
  • 连接到没有元数据的网络服务

    我想连接到此网络服务 https training api temando com schema 2009 06 server wsdl https training api temando com schema 2009 06 serve
  • PHP Session Id 在页面之间发生变化

    我有一个问题 我在 2 个页面之间丢失了 PHP 会话 session start 包含在一个名为 session inc php 的文件中 该文件包含在每个需要设置会话的页面中 这适用于网站上除一个特定页面 member profile

随机推荐