function CreateAndStartDataExtensionImport($dataExtensionCustomerKey, $fileName, $overwrite) { $import = new ET_Import(); $import->authStub = $this; $import->props = array("Name" => "SDK Generated Import " . uniqid()); $import->props["CustomerKey"] = uniqid(); $import->props["Description"] = "SDK Generated Import"; $import->props["AllowErrors"] = "true"; $import->props["DestinationObject"] = array("ObjectID" => $dataExtensionCustomerKey); $import->props["FieldMappingType"] = "InferFromColumnHeadings"; $import->props["FileSpec"] = $fileName; $import->props["FileType"] = "CSV"; $import->props["RetrieveFileTransferLocation"] = array("CustomerKey" => "ExactTarget Enhanced FTP"); if ($overwrite) { $import->props["UpdateType"] = "Overwrite"; } else { $import->props["UpdateType"] = "AddAndUpdate"; } $result = $import->post(); if ($result->status) { return $import->start(); } else { throw new Exception("Unable to create import definition due to: " . print_r($result, true)); } }
print "Checking status in loop \n"; # Wait a bit before checking the status to give it time to process sleep(15); $statusResponse = $startImport->status(); print_r('Status Status: ' . ($statusResponse->status ? 'true' : 'false') . "\n"); print 'Code: ' . $statusResponse->code . "\n"; print 'Message: ' . $statusResponse->message . "\n"; print 'Results Length: ' . count($statusResponse->results) . "\n"; print 'Results: ' . "\n"; print_r($statusResponse->results); print "\n---------------\n"; $importStatus = $statusResponse->results[0]->ImportStatus; } } print "Delete Import\n"; $deleteImport = new ET_Import(); $deleteImport->authStub = $myclient; $deleteImport->props = array("CustomerKey" => $NewImportName); $deleteResponse = $deleteImport->delete(); print_r('Delete Status: ' . ($deleteResponse->status ? 'true' : 'false') . "\n"); print 'Code: ' . $deleteResponse->code . "\n"; print 'Message: ' . $deleteResponse->message . "\n"; print 'Results Length: ' . count($deleteResponse->results) . "\n"; print 'Results: ' . "\n"; print_r($deleteResponse->results); print "\n---------------\n"; } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } ?>