Created
July 17, 2009 17:04
-
-
Save streamsend/149167 to your computer and use it in GitHub Desktop.
How to upload and import a lot of people at once
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <? | |
| // Load the PHP API library. | |
| require_once 'streamsend-php/src/streamsend.php'; | |
| // Replace these with your actual API Login ID (username) and Key (password). | |
| // Refer to http://app.streamsend.com/docs/api/index.html for more information. | |
| define('STREAMSEND_USERNAME', 'abc'); | |
| define('STREAMSEND_PASSWORD', '123'); | |
| // Fetch your audience. (You only have one.) | |
| $audience = SSAudience::find('first'); | |
| // Initialize a new file upload. Customize the filename to point to the full | |
| // local path of your comma- or tab-delimited data file. | |
| $upload = new SSUpload(array('filename' => dirname(__FILE__) . '/test.csv')); | |
| // Create the upload object. This triggers the uploading of the file to | |
| // StreamSend. | |
| // | |
| // NOTE: Because this could take a while, it should ideally be done separately | |
| // from the user interface so that your users don't have to wait for it. | |
| $upload->save(); | |
| // Initialize a new import using the upload you just created. Please refer | |
| // to the full API documentation for information on what all the available | |
| // attributes are and their possible values. | |
| $import = new SSImport(array( | |
| 'audience_id' => $audience->id(), | |
| 'columns' => array( | |
| 'email_address', | |
| 2, | |
| 12 | |
| ), | |
| 'upload_id' => $upload->id(), | |
| 'separator' => 'Comma', | |
| 'reactivate' => 'false', | |
| 'skip_blank_columns' => 'false', | |
| 'ignore_first_row' => 'false' | |
| )); | |
| // Create the import, thereby triggering the import process. | |
| $import->save(); | |
| // NOTE: Your people have not been added yet! Successful creation | |
| // of an import object only means that import has *started*. Since | |
| // this process can take upwards of many minutes (depending on the | |
| // size of the file and the size of your audience) the actual | |
| // import is done separately from creation so that your script is | |
| // not forced to wait for it to complete. | |
| // | |
| // If you need to know when the import is complete, you will need to | |
| // poll the API for its status at a regular interval. This is as | |
| // simple as reloading the object every so often until the import is | |
| // complete. Again, because this may take some time, it too should | |
| // be done in a background process detached from the user interface. | |
| do | |
| { | |
| sleep(10); // seconds | |
| $import->reload(); | |
| } | |
| while ($import->pending()); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment