2

I want to add SalesOrder through vTiger webservice. I'm using for this vtwsclib. Here is the code:

<?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']);
}

}
?>

And I get only: "ACCESS_DENIED : Permission to perform the operation is denied for id".

Account_id exists in database. Other SalesOrder was added with the same account_id but through webpage. I have also tried variant with accout_id = "6x46" where 6 is module_id. It also didn't work. Any ideas how to solve this problem?

Kamil Kwiecien
  • 51
  • 1
  • 10
  • is your salesorder table primary key has autoincrement behaviour? what is the name of primary key field in salesorder – Piyas De Mar 20 '13 at 18:49
  • It's accountid but when I change that in code I get other type of error, that field account_id is required. – Kamil Kwiecien Mar 20 '13 at 19:50

3 Answers3

3

I think you should be trying 11x46 for account id. Vtiger web services entity id's are different from tabids.

To get a correct list of all entity ids, execute this in your MySQL for the CRM:

select id, name from vtiger_ws_entity;
eldarerathis
  • 35,455
  • 10
  • 90
  • 93
S.T.Prasad
  • 31
  • 2
0

Problem lies in vtiger documentation. add entityName parameter in GET request.

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

This worked well for me. Although still couldn't understand that by giving any entityName or garbage string, program works !!! Please comment if you know more about this.

Ganesh Bhosale
  • 2,000
  • 18
  • 21
0

I think it's a bug in @Vtiger's web service. You can change the file named Create.php as following: (add the code between *)

    foreach ($referenceFields as $fieldName => $details) {
    if (isset($element[$fieldName]) && strlen($element[$fieldName]) > 0) {
        *if($fieldName == 'roleid' || $fieldName == 'currency_id'){
            continue;                    
       }*
        $ids = vtws_getIdComponents($element[$fieldName]);
        $elemTypeId = $ids[0];
        $elemId = $ids[1];                
        $referenceObject = VtigerWebserviceObject::fromId($adb, $elemTypeId);
        if (!in_array($referenceObject->getEntityName(), $details)) {
            throw new WebServiceException(WebServiceErrorCode::$REFERENCEINVALID,
                    "Invalid reference specified for $fieldName");
        }
        if ($referenceObject->getEntityName() == 'Users') {
            if(!$meta->hasAssignPrivilege($element[$fieldName])) {
                throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Cannot assign record to the given user");
            }
        }
        if (!in_array($referenceObject->getEntityName(), $types['types']) && $referenceObject->getEntityName() != 'Users') {
            throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED,
                    "Permission to access reference type is denied" . $referenceObject->getEntityName());
        }
    } else if ($element[$fieldName] !== NULL) {
        unset($element[$fieldName]);
    }
}   
James Risner
  • 5,451
  • 11
  • 25
  • 47