How to update the documents_account table from REST api

When upload document for certain account, the documents_accounts table stores both account id and document id. When upload the file from REST api, need to store the account_id and document_id in document_accounts table, but i can't store those values.(Want to relate the accounts and documents)

here is my sample code

$set_entry_parameters = array(

        "session" => $_SESSION['id'],

        "module_name" => "documents_accounts",

        "name_value_list" => array(

        array("name" => "document_id", "value" => $some_id),

        ),

        );

      

        //var_dump($set_entry_parameters);

        $set_entry_result = call("set_entry", $set_entry_parameters, $url);

Parents
  • To set a relationship in the legacy web services you must use a set_relationship call as described in

    http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Application_Framework/Web_Services/M…

    set_entry can only be used for new entries in a module.

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH

  • Try this piece of code (change acount_id and document_id to values in your environment):

    <?php

    $sugarUrl = 'http://localhost/sugarce65/service/v4_1/rest.php';

    $user = 'admin';

    $pass = 'admin';

    $loginParams = array(

      'user_auth' => array(

        'user_name' => $user,

        'password' => md5($pass),

        ),

      'application_name' => 'MY APP',

      'name_value_list' => array(),

    );

    $loginResult = rest_call($sugarUrl,'login',$loginParams);

    $sessionID = $loginResult->id;

    echo "SESSION ID=".$sessionID."<br>";

    $docid = 'b301090f-c88a-edc0-da03-56852dbee4cf';

    $accId = '620602ff-f6b7-6a05-99b9-5491650b3b18';

    $setParams = array(

      'session' => $sessionID,

      'module_name' => 'Documents',

      'module_id' => $docid,

      'link_filed_name' => 'accounts',

      'related_ids' => array($accId),

      'name_value_list' => array(),

      'delete' => 0,

    );

    $linkResult = rest_call($sugarUrl,'set_relationship',$setParams);

    if ($linkResult->created) echo "LINK created<br>";

    if ($linkResult->deleted) echo "LINK deleted<br>";

    if ($linkResult->failed)  echo "LINK failed<br>";

    echo("done");

    function rest_call($sugarUrl,$method,$params)

    {

      $curl = curl_init($sugarUrl);

      curl_setopt($curl, CURLOPT_POST, true);

      curl_setopt($curl, CURLOPT_HEADER, false);

      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        $Json = json_encode($params);

        $PostArgs = array(

        'method' => $method,

        'input_type' => 'JSON',

        'response_type' => 'JSON',

        'rest_data' => $Json,

        );

       

        curl_setopt($curl, CURLOPT_POSTFIELDS, $PostArgs);

        $Response = curl_exec($curl);

        curl_close($curl);

        $Result = json_decode($Response);

      return $Result;

    }

    ?>

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH

Reply
  • Try this piece of code (change acount_id and document_id to values in your environment):

    <?php

    $sugarUrl = 'http://localhost/sugarce65/service/v4_1/rest.php';

    $user = 'admin';

    $pass = 'admin';

    $loginParams = array(

      'user_auth' => array(

        'user_name' => $user,

        'password' => md5($pass),

        ),

      'application_name' => 'MY APP',

      'name_value_list' => array(),

    );

    $loginResult = rest_call($sugarUrl,'login',$loginParams);

    $sessionID = $loginResult->id;

    echo "SESSION ID=".$sessionID."<br>";

    $docid = 'b301090f-c88a-edc0-da03-56852dbee4cf';

    $accId = '620602ff-f6b7-6a05-99b9-5491650b3b18';

    $setParams = array(

      'session' => $sessionID,

      'module_name' => 'Documents',

      'module_id' => $docid,

      'link_filed_name' => 'accounts',

      'related_ids' => array($accId),

      'name_value_list' => array(),

      'delete' => 0,

    );

    $linkResult = rest_call($sugarUrl,'set_relationship',$setParams);

    if ($linkResult->created) echo "LINK created<br>";

    if ($linkResult->deleted) echo "LINK deleted<br>";

    if ($linkResult->failed)  echo "LINK failed<br>";

    echo("done");

    function rest_call($sugarUrl,$method,$params)

    {

      $curl = curl_init($sugarUrl);

      curl_setopt($curl, CURLOPT_POST, true);

      curl_setopt($curl, CURLOPT_HEADER, false);

      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        $Json = json_encode($params);

        $PostArgs = array(

        'method' => $method,

        'input_type' => 'JSON',

        'response_type' => 'JSON',

        'rest_data' => $Json,

        );

       

        curl_setopt($curl, CURLOPT_POSTFIELDS, $PostArgs);

        $Response = curl_exec($curl);

        curl_close($curl);

        $Result = json_decode($Response);

      return $Result;

    }

    ?>

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH

Children