Create and Perform a query with PHP SOAP API in ExactTarget

I have a code snippet that I try to create a query and perform it. I am able to create the query but it does not perform the query. Instead, it gives that error: Exception occurred during [Schedule::Start]

    $pr = new ExactTarget_PerformRequestMsg();

    $pr->Action = "Start"; 
    $pr->Definitions =  array();

    $qd = new ExactTarget_QueryDefinition();
    $qd->Name = "de_sql";
    $qd->CustomerKey = "de_sql";
    $qd->Description = "API_Query";
    $qd->TargetUpdateType = "Overwrite";                                   
    $qd->TargetType = "DE";
    $qd->QueryText = "SELECT sub.Localization, sub.SubscriberKey FROM ( SELECT a.SubscriberKey, a.Localization, row_number() OVER (PARTITION BY a.Localization ORDER BY a.SubscriberKey desc) as rowindex FROM " . $filter . " a WHERE a.SubscriberKey IN (SELECT SubscriberKey FROM ENT._Subscribers WHERE Status = 'Active') ) sub WHERE rowindex = 1 ";                    
    $ibo = new ExactTarget_InteractionBaseObject();
    $ibo->CustomerKey = "EF967E69-CD41-40F2-A896-4362802B7B79";
    $ibo->Name = "prooflist_test";                                                               
    $qd->DataExtensionTarget = $ibo;                                                                                                      

    $object = new SoapVar($qd, SOAP_ENC_OBJECT, 'QueryDefinition', "");

    $request = new ExactTarget_CreateRequest();
    $request->Options = NULL;
    $request->Objects = array($object);
    $results = $client->Create($request);
    $p_results = array($results);

    $pr->Definitions[] = new SoapVar($qd, SOAP_ENC_OBJECT, 'QueryDefinition', "");
    $pr->Options = NULL;
    $results2 = $client->Perform($pr);


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can’t just perform the QueryDefinition using the CustomerKey,
you must use the ObjectID for the Query definition.

You can find the ObjectID by performing a retrieve on the QueryDefinition Object. Below is a sample SOAP Body envelope to retrieve QueryDefinition object.

<s:Body xmlns:xsd="" xmlns:xsi="">
  <RetrieveRequestMsg xmlns="">
           <ClientID>BU MID here</ClientID>
        <Filter xsi:type="SimpleFilterPart">
           <Value>Query External Key here</Value>
        <Retrieves />

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x