Php vTiger Web服务”一词;访问被拒绝:对id执行操作的权限被拒绝;

Php vTiger Web服务”一词;访问被拒绝:对id执行操作的权限被拒绝;,php,web-services,api,vtiger,Php,Web Services,Api,Vtiger,我想通过vTiger webservice添加SalesOrder。我正在使用这个vtwsclib。代码如下: <?php include_once('vtwsclib/Vtiger/WSClient.php'); $url = 'http://localhost:8888'; $client = new Vtiger_WSClient($url); $login = $client->doLogin('admin', 'zzzzzzzz'); if(!$login) echo 'L

我想通过vTiger webservice添加SalesOrder。我正在使用这个vtwsclib。代码如下:

<?php
include_once('vtwsclib/Vtiger/WSClient.php');
$url = 'http://localhost:8888';
$client = new Vtiger_WSClient($url);
$login = $client->doLogin('admin', 'zzzzzzzz');
if(!$login) echo 'Login Failed';
else {

    $data = array(
        'subject' => 'Test SalesOrder',
        'sostatus' => 'Created',
        'invoicestatus'=>'AutoCreated',
        'account_id'=> '46', // Existing account id
        'bill_street' => 'Bill Street',
        'ship_street' => 'Ship Street',
    );
    $record = $client->doCreate('SalesOrder', $data);

$error = $client->lasterror();
    if($error) {
    echo $error['code'] . ' : ' . $error['message'];
}

if($record) {
    $salesorderid = $client->getRecordId($record['id']);
}

}
?>

我只得到:“访问被拒绝:执行操作的权限被id拒绝”


数据库中存在帐户id。其他SalesOrder是通过网页以相同的帐户id添加的。我还尝试过accout_id=“6x46”的变体,其中6是模块id。它也不起作用。有没有办法解决这个问题?

我想您应该尝试使用11x46作为帐户id。Vtiger web服务实体id不同于选项卡id

要获得所有实体ID的正确列表,请在CRM的MySQL中执行以下操作:

select id, name from vtiger_ws_entity;

问题在于vtiger文档。 在GET请求中添加entityName参数

var q = "select * from Users;";
"http://vtigercrm/webservice.php?operation=query&sessionName=ABC&entityName=XYZ&query="+q

这对我很有效。尽管仍然无法理解,通过提供任何entityName或垃圾字符串,程序可以工作!!!如果您对此了解更多,请发表评论。

这是一种可能帮助您生成查询的方法
q

"http://vtigercrm/webservice.php?operation=query&sessionName=ABC&query="+q
例如,您期望:

SELECT * FROM INVOICE WEHRE id='72xxx';
你能行

buildVtigerQuery('INVOICE', ['id' => '72xx']);
这就是功能:

    protected function buildQuery(
    string $moduleName,
    array $filterData = [],
    string $attributes = '*',
    int $start = 0,
    int $limit = null
): string {
    $query = 'SELECT ' . $attributes . ' FROM ' . $moduleName . ' ';
    if (!empty($filterData)) {
        $query .= 'WHERE ';
        foreach ($filterData as $key => $value) {
            $whereOperator = (is_numeric($value) === true) ? ' = ' : ' like ';
            $value = (is_numeric($value) === true) ? $value : '%' . $value . '%';
            $query .= $key . $whereOperator . '\'' . $value . '\'' . ' AND WHERE ';
        }
    }

    if (substr($query, -11) === ' AND WHERE ') {
        $query = substr_replace($query, "", -11);
    }

    if ((!is_null($limit)) && (0 < $start)) {
        $query .= ' ORDER BY id LIMIT ' . $start . ',' . $limit;
    }


    if (!is_null($limit) && (0 >= $start)) {
        $query .= ' ORDER BY id LIMIT ' . $limit;
    }


    return $query . ';';
}
受保护的函数buildQuery(
字符串$moduleName,
数组$filterData=[],
字符串$attributes='*',
int$start=0,
int$limit=null
):字符串{
$query='从'$moduleName'中选择'$attributes';
如果(!空($filterData)){
$query.='WHERE';
foreach($filterData作为$key=>$value){
$whereOperator=(是数值($value)==true)?“=”:“类似”;
$value=(是数值($value)==true)?$value:“.”.$value.“%”;
$query.=$key.$whereOperator.'\'.$value.'\'.'和WHERE';
}
}
if(substr($query,-11)=='和其中'){
$query=substr\u replace($query,“,-11);
}
如果((!is_null($limit))&&(0<$start)){
$query.='ORDER BY id LIMIT'.$start'.','.$LIMIT;
}
如果(!为null($limit)&&(0>=$start)){
$query.='ORDER BY id LIMIT'。$LIMIT;
}
返回$query。“;”;
}

我没有考虑XSS注入,因为我预期的查询
q
将写入url

salesorder表主键是否具有自动增量行为?SalesOrder中主键字段的名称是什么?它是accountid,但当我在代码中更改该字段时,会出现其他类型的错误,该字段的account_id是必需的。请解释您的代码行,以便其他用户能够理解其功能。谢谢