Hi folks,
I have been trying to figure this out for the last few days, and it's really getting me nowhere. I'm pretty new to PHP and really new to cURL.

I'm trying to connect to my highrise account via their API

I'm trying to implement this through php. Browsing their forums, I came across these two code examples and they work fine:

<?php

$request = '<person>
<first-name>John</first-name>
<last-name>Doe</last-name>
<title>CEO</title>
<company-name>Doe Inc.</company-name>
<background>A popular guy for random data</background>
<contact-data>
 <email-addresses>
  <email-address>
   john.doe@example.com
        <location>Work</location>
   </email-address>
  </email-addresses>
<phone-numbers>
 <phone-number>
  <number>555-555-5555</number>
   <location>Work</location>
 </phone-number>
 <phone-number>
  <number>555-666-6666</number>
   <location>Home</location>
  </phone-number>
 </phone-numbers>
</contact-data>
</person>';

// Create Headers

$header[] = "Content-type: application/xml";

$ch = curl_init("http://rattletree.highrisehq.com/people.xml");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERPWD, "activationtoken:password");
curl_setopt($ch, CURLOPT_GET, TRUE); // Set cUrl to post
curl_setopt($ch, CURLOPT_HTTPHEADER, $header ); //Include the head info – this is important must be application/xml
curl_setopt($ch, CURLOPT_POSTFIELDS, $request); //includes the xml request
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); // return into a variable

$data = curl_exec($ch);
curl_close($ch);

echo $data;

If you only want to retrieve information it would look more like this:



$ch = curl_init("http://rattletree.highrisehq.com/people.xml");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERPWD, "activation-token:password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); // return into a variable

$data = curl_exec($ch);
curl_close($ch);

echo $data;
?>

So the first example above will create a new contact in highrise, and the second example will get all the contacts and almost all their details.

What I'm trying to do is figure out how to modify the second example to also include the "notes" that are associated with a user...

This page shows it is available in the API, but I just don't know enough of PHP or cURL to put the pieces together.

I really appreciate any help.

I'm not wanting to tackle this yet, but in case it changes the solution, once I get all this data, I will be parsing it and putting it in my own backup mySQL.

Thanks,
Joel

Thank you for posting that. Here's my confusion though:

The example here:

$ch = curl_init("http://rattletree.highrisehq.com/people.xml");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERPWD, "activation-token:password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); // return into a variable
$data = curl_exec($ch);
curl_close($ch);
echo $data;

That above code will give me any xml of all of my contacts (around 300 people).

The code example you gave will give me the notes for one individual.

Is there a way to retrieve the notes for each contact all at once?

When I run the above code, I get a list of all contacts in this form:

<person>
    <author-id type="integer">70821</author-id>

    <background>A popular guy for random data</background>
    <company-id type="integer">28344796</company-id>
    <created-at type="datetime">2009-12-15T07:18:48Z</created-at>
    <first-name>John</first-name>
    <group-id type="integer" nil="true"></group-id>
    <id type="integer">28345031</id>

    <last-name>Doe</last-name>
    <owner-id type="integer" nil="true"></owner-id>
    <title>CEO</title>
    <updated-at type="datetime">2009-12-15T07:18:48Z</updated-at>
    <visible-to>Everyone</visible-to>
<contact-data>
  <phone-numbers type="array">

    <phone-number>
      <id type="integer">24242909</id>
      <location>Work</location>
      <number>555-555-5555</number>
    </phone-number>
    <phone-number>
      <id type="integer">24242910</id>

      <location>Home</location>
      <number>555-666-6666</number>
    </phone-number>
  </phone-numbers>
  <web-addresses type="array"/>
  <email-addresses type="array"/>
  <addresses type="array"/>
  <instant-messengers type="array"/>

  <twitter-accounts type="array"/>
</contact-data>
  </person>

Do I then need to build a script that will parse the <id> and put it into your supplied code?

Still struggling with this and not having luck.

There are holes in my understanding that are not being filled with the cURL tutorials I'm seeing...:-(

Here are a few questions:

1) Can I somehow get the data from
http://rattletree.highrisehq.com/people.xml http://rattletree.highrisehq.com/people/$id/notes.xml
and http://rattletree.highrisehq.com/people/$id/emails.xml
and then merge all that information within one file?

2) Once I have done that, I have been trying to parse all the information to view it in a browser, but maybe I don't need to do that? The end goal is to just take that information and stuff it in a database.

Thanks for your help. I have managed to piece together a working cURL import, and then it saves the file, and then prints using simplexml, so the elements are now parsed in the arrays, etc...

<?php
$curl = curl_init("http://rattletree.highrisehq.com/people.xml");
$fp = fopen("test.xml", "w");
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_USERPWD, "authorization_key:X");
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_exec ($curl);
curl_close ($curl);

 ?>

<?php
// The file test.xml contains an XML document with a root element
// and at least an element /[root]/title.

if (file_exists('test.xml')) {
    $xml = simplexml_load_file('test.xml');

    print_r($xml);
} else {
    exit('Failed to open test.xml.');
}
?>

Here is an example of the gobblygook I get when running the above code (I believe this is one "node"):

SimpleXMLElement Object ( [@attributes] => Array ( [type] => array ) [person] => Array ( [0] => SimpleXMLElement Object ( [author-id] => 70821 [background] => ghjfj [company-id] => 8257787 [created-at] => 2008-06-24T18:36:33Z [first-name] => adrian [group-id] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => integer [nil] => true ) ) [id] => 7979920 [last-name] => SimpleXMLElement Object ( ) [owner-id] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => integer [nil] => true ) ) [title] => SimpleXMLElement Object ( ) [updated-at] => 2009-12-15T07:04:16Z [visible-to] => Everyone [contact-data] => SimpleXMLElement Object ( [instant-messengers] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => array ) ) [twitter-accounts] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => array ) ) [email-addresses] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => array ) [email-address] => SimpleXMLElement Object ( [address] => adrian@orangeshow.org [id] => 3585151 [location] => Work ) ) [addresses] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => array ) ) [phone-numbers] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => array ) ) [web-addresses] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => array ) ) ) )

What would be my next step to now take this information and get into my mySQL database?

Thank you for your help!
Joel

I'm assuming you already have a database holding tables with the correct columns for the data you are getting. So in theory, you'd store each person from the xml into the database using simplexml and queries.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.