AnsweredAssumed Answered

REST Api creating a relationship between accounts and contacts

Question asked by Andrew Collins on Jun 13, 2016
Latest reply on Jun 15, 2016 by Tevfik Tümer

I have been trying to create a relationship between account and contacts under the "account name" in the contacts section like this:

 

        public function addContact($accountId){


            $set_entry_parameters = array(
                //session id
                "session" => $this->session,
                //The name of the module from which to retrieve records.
                "module_name" => "Contacts",
                //Record attributes
                "name_value_list" => array(
                    //to update a record, you will nee to pass in a record id as commented below
                    //array("name" => "id", "value" => "9b170af9-3080-e22b-fbc1-4fea74def88f"),
                    array("name" => "salutation", "value" => $_POST['rc_title']),
                    array("name" => "first_name", "value" => $_POST['rc_firstName']),
                    array("name" => "last_name", "value" => $_POST['rc_lastName']),
                    array("name" => "title", "value" => $_POST['rc_jobTitle']),
                    array("name" => "phone_mobile", "value" => $_POST['rc_mobileNumber']),
                    array("name" => "email1", "value" => $_POST['rc_email'])
                )
            );


            $set_entry_result = $this->call("set_entry", $set_entry_parameters, $this->urlEndPoint);


            $contact_id = $set_entry_result->id;


            $set_relationship_parameters = array(
                //session id
                "session" => $this->session,
                //The name of the module from which to retrieve records.
                "module_name" => "Contacts",
                "module_id" => $contact_id,
                "link_field_name" => "account_name",
                "related_ids" => array($accountId)
            );


            $set_relationship_result = $this->call("set_relationship", $set_relationship_parameters, $this->urlEndPoint);


            echo "<pre>";
            print_r($set_relationship_result);
            echo "</pre>";
        }

 

and then get returned:

 

stdClass Object
(
  [created] => 0
  [failed] => 1
  [deleted] => 0
)

 

This doesn't seem to work, and I'm not entirely sure why either. The documentation on the setting of relationships doesn't seem to great either.

Outcomes