Perform batch functions using PHP API


  1. <?php
  2. require_once("panacea_api.php");
  3. $api = new PanaceaApi();
  4. $api->setUsername("demouser");
  5. $api->setPassword("demouser");

  6. $file = "../generic/mybatch.csv";

  7. $result = $api->batch_create("My batch name", $file);

  8. if($api->ok($result)) {
  9. /* Batch created ! */

  10. $batch_id = $result['details'];

  11. echo "Batch created with ID {$batch_id}\n";

  12. /* Let's create another one from XLS */

  13. $file = "../generic/mybatch.xls";

  14. $result = $api->batch_create("My second batch", $file, 0, false, 'xls');

  15. if($api->ok($result)) {
  16. echo "XLS Batch created!\n";

  17. /* Give it a moment to parse */
  18. sleep(1);

  19. $status = $api->batch_check_status($result['details']);






  20. if($status['details']['status'] == 32) { // Is it currently paused and waiting?
  21. $api->batch_start($result['details']);

  22. /* Let's wait a while and see if it's done */

  23. sleep(2);

  24. $status = $api->batch_check_status($result['details']);

  25. }

  26. }


  27. }

  28. ?>