tags:

views:

177

answers:

2

I'm integrating my website with a third party system. Here's the workflow between my website and the third party system:

1) From my website, I use PHP to automate upload of a CSV file to the third party system.

2) After the third party system receives my file, it will conduct a few operations.

3) The third party system will email [email protected] a list of successful and failed operations including any error messages.

4) My website needs to record the list of successful/failed operations in the confirmation email.

5) My website performs operations based on which items were successful/failed in the confirmation email.

First question: What do I need to research to be able to implement #4?

Second question: Is parsing a confirmation email the best way to record the successful/failed operations of the 3rd party system? It feels like a problematic way of getting to step 5 (for example, what if the language in the email changes? Then i have to rewrite the parser".

+3  A: 

Well, obviously a better way would be some sort of push from the 3rd party system to a script on your end, following a defined convention of parameters. If there is any chance to do so, talk to the 3rd party whether such a way can't be implemented somehow. It could be very little work on their end.

To parse E-Mail: The standard method in PHP to check POP3 and IMAP mailboxes is here

What you need to parse the E-Mails themselves depends on what they look like. Probably regular expressions will be involved.

Pekka
As Pekka mentioned re. a "script on your end", and for background research on the fundamentals of building your own API see http://www.codewalkers.com/c/a/Miscellaneous/Create-Your-Own-Custom-API/ (via http://stackoverflow.com/questions/1906255/create-api-using-php )
micahwittman
+1  A: 

I've done a similar setup to this. Setting up a mailbox to receive the output from another system is certainly not the most fail proof setup, but sometimes there are no other options.

Zend_Mail makes this a breeze. My whole script for checking the mail inbox was just a few lines:

 $mail = new Zend_Mail_Storage_Imap(array(
  'host' => $config->reports->email->incoming,
  'user' => $config->reports->email->address,
  'password' => $config->reports->email->password
 ));

 foreach ($mail as $message) {
        $message->getContent(); // Do something with the message content
  if ($message->isMultipart()) {
   $part = $message->getPart(2); // Deal with attachment, 
                                          // if your output is an  
                                          // attachment
   if ($part->contentTransferEncoding=='base64') {
    $raw = base64_decode($part->getContent());
    // Do something with the attachment data
   }
  }
 }

Since you're parsing HTML, passing this off to a DOM parser would be the next logical step.

Andy Baird
thanks this is a useful snippet of code!
John