Results 1 to 2 of 2

Thread: How to Add Relationship Through Rest In SugarCRM

  1. #1
    madhusudan2291 Guest

    Default How to Add Relationship Through Rest In SugarCRM

    Hi
    I am using one-to-many relationship between Contact And CountryCity Module And I need to add a relationship to this using REST,

    I have used following code to create a relationship between these two

    <?php

    $url = "localhost/RealEstateAgentCRM/service/v4/rest.php";

    $username = "admin";
    $password = "admin";
    function call($method, $parameters, $url)
    {
    ob_start();
    $curl_request = curl_init();
    curl_setopt($curl_request, CURLOPT_URL, $url);
    curl_setopt($curl_request, CURLOPT_POST, 1);
    curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    curl_setopt($curl_request, CURLOPT_HEADER, 1);
    curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);
    $jsonEncodedData = json_encode($parameters);
    $post = array(
    "method" => $method,
    "input_type" => "JSON",
    "response_type" => "JSON",
    "rest_data" => $jsonEncodedData
    );
    curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post);
    $result = curl_exec($curl_request);
    curl_close($curl_request);
    $result = explode("\r\n\r\n", $result, 2);
    $response = json_decode($result[1]);
    ob_end_flush();
    return $response;
    }
    $login_parameters = array(
    "user_auth"=>array(
    "user_name"=>$username,
    "password"=>md5($password),
    "version"=>"1"
    ),
    "application_name"=>"RestTest",
    "name_value_list"=>array(),
    );
    $login_result = call("login", $login_parameters, $url);
    $session_id = $login_result->id;


    $parameters = array(
    'session' => $session_id,
    'module_id' => '3671da49-2d13-aa21-7h49-519b11dgu34', // This is a contact Id
    'module_name' => 'Contacts',
    'link_field_name' => 'contacts_veon_country_city_list_1',
    'related_ids' => array('3904da49-2d13-aa21-72a9-519b11d43b02'), // This is a City-Country id
    );

    $add_relationship_result = call("set_relationship", $parameters, $url);
    print_r($add_relationship_result);

    ?>



    Regards

    Madhusudan Singh

  2. #2
    madhusudan2291 Guest

    Default Re: How to Add Relationship Through Rest In SugarCRM

    I had also tried REST Examples From this link IBM notice: The page you requested cannot be displayed
    but still its not working i am getting following error if I use the codes mention in the above link

    Warning: curl_exec() expects parameter 1 to be resource,

    Regards
    Madhusudan Singh

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help: Javascript Rest Sugarcrm
    By chrisandrews in forum Developer Help
    Replies: 0
    Last Post: 2013-04-28, 06:17 PM
  2. Insert Records In Relationship table Using REST
    By madhusudan2291 in forum Developer Help
    Replies: 4
    Last Post: 2013-03-23, 03:44 AM
  3. Insert a many to many relationship with REST API
    By Shot89 in forum Developer Help
    Replies: 6
    Last Post: 2012-04-16, 08:24 PM
  4. Replies: 0
    Last Post: 2012-02-15, 07:51 AM
  5. Rest Api Of SugarCRM
    By karan5037 in forum General Discussion
    Replies: 0
    Last Post: 2009-10-21, 05:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •