Discussion Forums

Link Contact to Company with Web Form

 
Avatar
New Member
5 posts

Ok, I can import a contact, I can import a company, my form submits both, but how do I link the contact to the company from within the web form?

Also, A loop to check for an existing contact ID would be nice. So that it would update a contact from the submission rather than creating a new duplicate.

Any Ideas?

Avatar
Lyncean
124 posts

Greetings, Saeros.

Saeros - Mar 14, 2010 05:19pm

Ok, I can import a contact, I can import a company, my form submits both, but how do I link the contact to the company from within the web form?

You can find the answer in the contacts api documentation:

to link the item to one or more contacts, companies or project blogs use <relateditems><add><relatedto><id>{relatedtoid}</id></relatedto>...</add></relateditems>

So, if you use our example, please add related companies as in the following example:

  //
  // Adding the contact
  //
 
  $contactData = array(
      ‘firstname’    => $requestData[‘firstname’],
      ‘lastname’    => $requestData[‘lastname’],
      ‘jobtitle’    => $requestData[‘jobtitle’],
      ‘businessemail’ => $requestData[‘businessemail’],

      // Related companies
      ‘relateditems’  => array(
        ‘add’ => array(‘relatedto’ => array({companyId}))
      ),
  );

Where {companyId} is the ID of the company you want to link your new contact with.
If you don’t use our example, just prepare the xml (json, form encoded data if you use one of these) according to the documentation e.g

<request>
  <firstname>Aaron</firstname>
  <lastname>Baileys</lastname>         
  <relateditems>
      <add>
        <relatedto>315890</relatedto>
      </add>
  </relateditems>
  ...
</request>

Saeros - Mar 14, 2010 05:19pm

Also, A loop to check for an existing contact ID would be nice. So that it would update a contact from the submission rather than creating a new duplicate.

You can use GET https://secure.solve360.com/contacts which returns a collection of contacts that match the requested criteria, please check the docs and the ‘examples’ section.
If you use our php library the code should be something like:

$searchOptions = array(
  ‘limit’    => 10000000,
  ‘filtermode’  => ‘’,
  ‘filtervalue’  => ‘’,
  ‘searchmode’  => ‘Cany’,
  ‘searchvalue’ => ‘John Smith’,
);

$contacts = $solve360Service->searchContacts($searchOptions);

if (count($contacts)) { // some contacts are found
  $contact = array_shift($contacts); // get the first one
  $id = (integer) $contact->id; // and here is the id that you can use
}

Avatar
New Member
5 posts

Thank you, this is great but I am having trouble with the searchContacts function. count($contacts) returns true even when no contact because the return value is not an array, it is xml, so the array_shift($contacts) function wont work either.

I am no php expert so I dont know how to convert xml to an array.

Avatar
Lyncean
124 posts
Saeros - Mar 15, 2010 03:16pm

Thank you, this is great but I am having trouble with the searchContacts function. count($contacts) returns true even when no contact because the return value is not an array, it is xml, so the array_shift($contacts) function wont work either.

I am no php expert so I dont know how to convert xml to an array.

I was assuming that you had some basic experience with PHP as far as you are trying to work with the API using it and my example was rough.

This will work:

  $searchOptions = array(
      ‘limit’  => 10000000,
      ‘filtermode’  => ‘’,
      ‘filtervalue’  => ‘’,
      ‘searchmode’  => ‘Cany’,
      ‘searchvalue’ => ‘John Smith’,
  );

  $contacts = $solve360Service->searchContacts($searchOptions);

  if ((integer) $contacts->count > 0) { // some contacts are found
      $contact = current($contacts->children()); // get the first one
      $id = (integer) $contact->id; // and here is the id that you can use
  }

Though you may need a PHP developer or just a person who is more experienced with PHP if you want to use it for more complex tasks in the future.

You welcome!

Avatar
New Member
5 posts

Thank you very much, it works great. I did it like this..

  // If Contact is found, edit Contact
if ((integer) $contacts->count > 0) { // some contacts are found
    $contact = current($contacts->children()); // get the first one
    $id = (integer) $contact->id; // and here is the id that you can use
       
        $type = ‘updated’;
        $contact = $solve360Service->editContact($id, $contactData);
        $contact = $solve360Service->getContact($id);  // Because edit returns no data
       
  // If Contact is not found, add Contact
      } else {
        $type = ‘added’;
        $contact = $solve360Service->addContact($contactData);
       
      }
     

If I had looked more closely I may not have bothered you. I just put what you gave me in, got an error, then posted.  I do have a little knowledge of PHP, just enough to get myself in too deep.

For years I have been doing all my CGI with Perl, I have been slow to make the transition to PHP.

Again thanks, your the best.

Avatar
New Member
5 posts
Alex - Mar 15, 2010 09:22am

    // Related companies
      ‘relateditems’  => array(
        ‘add’ => array(‘relatedto’ => array({companyId}))
      ),

 


NOTE: If someone else wants to use this, dont forget to add the “ array(‘id’ =>“ as in..

          // Related companies
          ‘relateditems’  => array(
              ‘add’ => array(‘relatedto’ => array(‘id’ => array($companyId)))
          ),

Avatar
Lyncean
124 posts

NOTE: If someone else wants to use this, dont forget to add the “ array(‘id’ =>“ as in..

          // Related companies
          ‘relateditems’  => array(
              ‘add’ => array(‘relatedto’ => array(‘id’ => array($companyId)))
          ),

Oh, that’s right, thanks for correcting me.