Q:

check if list exists in exacttarget API

I'm planning to create lists and add user details as subscribers to them using the exacttarget SOAP API in PHP. The code api has sample code on creating a list. I built my custom logic based on it as follows
public function createList($siteId, $siteDescription){
        try {
            $list = new ExactTarget_List();
            // $list->Description = "PHP Created List"; // List for the venue
            // $list->ListName = "PHP API Created List"; // Description about the list
            $list->Description = $siteDescription; // List for the venue
            $list->ListName = $siteId;
            $object = new SoapVar($list, SOAP_ENC_OBJECT, 'List', "http://exacttarget.com/wsdl/partnerAPI");
            $request = new ExactTarget_CreateRequest();
            $request->Options = NULL;
            $request->Objects = array($object);
            $results = $client->Create($request);
            if ($results->OverallStatus == 'OK') 
            {
                echo 'SUCCESS';
            }
            else
            {
            echo 'FAILED';
            }    
        }
        catch (SoapFault $e) {
            // var_dump(e);
            $this->success = 0;
        }
    }

But my workflow is such that in case list already exists I should proceed to next step of adding subscribers (doh!) to it else create the list first and add subscribers. I could not find any example code snippet on checking if the list exists or not using the code API doc and hence am wondering if this is possible at all. My meager understanding of SOAP and XML is playing big time here and hence requesting if any veterans who have better knowledge or idea on this share some details on it to aid my cause.

A:

You can grab all lists fairly easily - for instance, follow the code from the following ET technical doc:
http://docs.code.exacttarget.com/020_Web_Service_Guide/Technical_Articles/Retrieving_a_List_from_an_Account
The article is fairly good (relatively speaking, of course), and I can vouch for its accuracy. Here's the pertinent bit from the PHP section:
    $rr = new ExactTarget_RetrieveRequest();
    $rr->ObjectType = "List";   
    $rr->Properties =  array();
    $rr->Properties[] = "ID";
    $rr->Properties[] = "List.ListName";        
    $rr->Options = NULL;

    $rrm = new ExactTarget_RetrieveRequestMsg();
    $rrm->RetrieveRequest = $rr;        

    $results = $client->Retrieve($rrm);  
        var_dump($results);

To grab a specific list, you create a SimpleFilterPart object and attach it to your RetrieveRequest (note - this part is buggy, untested, terrible PHP code - I wrote it in Python and then translated it here - if you really really need help with this part, message me):
    $sfp=new ExactTarget_SimpleFilterPart;
    $sfp=>Property = "ListID";
    $sfp=>SimpleOperator = new ExactTarget_SimpleOperators->equals;
    $sfp=>Value = Array(contact_list);
    $retrieverequest=>Filter = $sfp;

Hope that saves some headache for someone.

