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("");
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("");
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

Dani AI

Generated

As already pointed out, the Highrise API does not include notes in the single people feed — you have to fetch per-person endpoints (notes, emails, etc.). That means the practical approach is a small ETL: pull the people list, extract each id, then request each person’s notes and contact endpoints and persist them locally. Below are concrete, low-risk steps and tips to get that working reliably.

  1. Fetch and parse the people feed, streaming if the file is large. For modest lists SimpleXML is fine; for hundreds/thousands use a streaming parser (XMLReader) so you do not run out of memory. Extract the id and updated-at fields; store those in a local table so subsequent runs can skip unchanged records.

  2. For each person id, GET /people/{id}/notes.xml and any other sub-resources. Do this in small batches and respect the API’s rate limits. To speed up imports you can either parallelize with PHP’s curl_multi functions or process sequentially with short sleeps; log failures and retry with exponential backoff.

  3. Data modeling & DB tips: normalize into people, emails, phones, notes tables keyed by the remote id. Use prepared statements (PDO) and transactions for bulk inserts. To avoid duplicates, use a unique constraint on remote_id and perform upserts with INSERT ... ON DUPLICATE KEY UPDATE or equivalent.

  4. Reliability and maintenance: run the import as a CLI/cron job rather than a web request (avoids timeouts). Store raw XML blobs for auditing, log progress so you can resume after a crash, and use updated-at to perform incremental syncs instead of reimporting everything every run.

References for safe, production-ready building blocks: PHP PDO for prepared statements and transactions (PDO manual), MySQL upserts (INSERT ... ON DUPLICATE KEY UPDATE), and PHP curl_multi for parallel requests (curl_multi_init). These patterns will make the per-person calls manageable and keep your import robust.

Recommended Answers

All 6 Replies

According to the specs it would be something like this:

$id = 1; // your person id for which you want to retrieve the notes
$ch = curl_init("");

You can find this example on the "Introduction" page.

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

The example here:

$ch = curl_init("");
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

and
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.

You cannot request all this information at once, because the API does not support it. You need to request everything separately and import it into your database part by part.

You can use for example http://php.net/manual/en/book.simplexml.php to parse the returned xml.

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("");
$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] => [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.