Answers.Body: <p>I suggest you use the api.</p>
  
  <p>Visiting yoursite.org/civicrm/api will let you try it out.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-10T03:33:41.983Z
Answers.Text: That link just takes me to the dashboard
Answers.UserDisplayName: Vietyank
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-10T15:50:52.970Z
Answers.Text: Maybe you are using an older version of Civi. Try yoursite.org/civicrm/api/explorer
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-11T04:09:52.453Z
Answers.Text: That worked but I have never written any php using the API. What I've got is a spreadsheet with a list of group ids I want to delete. There are about 400 of them so I really want to write a script. It looks like the API will do the trick and remove members from the groupas well but I need to find an example of how to write the PHP. This is CiviCRM 4.1.5.
  
  We are migrating to Nation Builder and need to delete these groups before the migration.
Answers.UserDisplayName: Vietyank
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-11T06:11:36.893Z
Answers.Text: Sorry...I cannot figure out how to put code in the comments
Answers.UserDisplayName: Vietyank
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-13T15:26:24.710Z
Answers.Text: Sorry to lose you to NB - enjoy their new higher prices.
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-08T18:21:44.277Z
Answers.LastActivityDate: 2015-10-08T18:21:44.277Z
Answers.UserDisplayName: Coleman
Answers.Body: <p>The challenge seems to be instantiating civicrm within a script - the easiest ways are</p>
  
  <p>1) through the api explorer
  2) through drush - ie drush eval"civicrm_initialize(); script lines here"
  3) through devel in the UI looks much like drush</p>
  
  <p>Otherwise for a standalone php script (that doesn't leverage drupal) you probably want to copy the way one of the scripts in the bin directory does it - but that way is more painful :-(</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-12T00:43:05.173Z
Answers.Text: This has to be run on a production system that does not have Drush installed, otherwise I could do it with Drush. I have seen other posts that other people had problems with CiviCRM initialize too
Answers.UserDisplayName: Vietyank
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-12T00:44:00.003Z
Answers.Text: Haha. I was looking for something not too painful for a newb.
Answers.UserDisplayName: Vietyank
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-12T07:19:09.703Z
Answers.Text: I'd still like to know how to do it with a standalone php script using the API
Answers.UserDisplayName: Vietyank
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-14T05:08:37.760Z
Answers.Text: While Eileen's answer was informative, I still was not able to write a php script using the API directly.
Answers.UserDisplayName: Vietyank
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-12T00:40:55.127Z
Answers.LastActivityDate: 2015-10-12T00:40:55.127Z
Answers.UserDisplayName: eileen
Answers.Body: <p>I got it to work by calling rest.php with wget wget -a delgroup.log -O delgroup.out 'example.com/sites/all/modules/civicrm/extern/…;</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-14T07:44:19.937Z
Answers.LastActivityDate: 2015-10-14T07:44:19.937Z
Answers.UserDisplayName: Vietyank
Answers.Body: <p>You could also use chaining in the api explorer ie.</p>
  
  <p>civicrm_api3('Group', 'get', array('id' => array('IN' => array(4,6,7,8,9), 'api.group.delete');</p>
  
  <p>But test thoroughly on dev first!!!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-12T19:46:48.897Z
Answers.Text: if that is the 'solution' then suggest you add as an answer ;-)
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-12T00:47:58.423Z
Answers.LastActivityDate: 2015-10-12T00:47:58.423Z
Answers.UserDisplayName: eileen
Body: <p>I have 300-400 CiviCRM smart groups I want to delete. I will know the id for the group but need to know what other tables I need to delete that may be related.</p>
  
  <p>Also, is there any way to identify which groups are smart groups?</p>
  
  <p>Here is some code I have tried.</p>
  
  <p><code>&lt;?php
  require_once 'api/class.api.php';
  $api = new civicrm_api3();
  $result = $api-&gt;group-&gt;delete ( $id=1544 );
  ?&gt;</code></p>
  
  <p>Here is the result:</p>
  
  <p><code>PHP Fatal error:  Class 'CRM_Core_Config' not found in /home/daweb_dev/democratsabroad/drupal/sites/all/modules/civicrm/api/class.api.php on line 92
  PHP Stack trace:
  PHP   1. {main}() /home/daweb_dev/democratsabroad/drupal/sites/all/modules/civicrm/delgroup.php:0
  PHP   2. civicrm_api3-&gt;__construct() /home/daweb_dev/democratsabroad/drupal/sites/all/modules/civicrm/delgroup.php:3</code></p>
  
  <p>This worked using rest.php</p>
  
  <p>wget -a delgroup.log -O delgroup.out '<a href="https://www.example.com/sites/all/modules/civicrm/extern/rest.php?entity=group&amp;action=delete&amp;key=site-key&amp;api_key=api-key&amp;version=3&amp;json=1&amp;id=923" rel="nofollow">https://www.example.com/sites/all/modules/civicrm/extern/rest.php?entity=group&amp;action=delete&amp;key=site-key&amp;api_key=api-key&amp;version=3&amp;json=1&amp;id=923</a>'</p>
  
Tags: <database><smartgroups>
Title: How to create script to delete smart groups
ThreadText: # How to create script to delete smart groups
  
  (Asked by: username_0 on 2015-10-07)
  
  I have 300-400 CiviCRM smart groups I want to delete. I will know the id for the group but need to know what other tables I need to delete that may be related.
  
  Also, is there any way to identify which groups are smart groups?
  
  Here is some code I have tried.
  
  `php
  require_once 'api/class.api.php';
  $api = new civicrm_api3();
  $result = $api-group->delete ( $id=1544 );
  ?>`
  
  Here is the result:
  
  `PHP Fatal error: Class 'CRM_Core_Config' not found in /home/daweb_dev/democratsabroad/drupal/sites/all/modules/civicrm/api/class.api.php on line 92
  PHP Stack trace:
  PHP 1. {main}() /home/daweb_dev/democratsabroad/drupal/sites/all/modules/civicrm/delgroup.php:0
  PHP 2. civicrm_api3->__construct() /home/daweb_dev/democratsabroad/drupal/sites/all/modules/civicrm/delgroup.php:3`
  
  This worked using rest.php
  
  wget -a delgroup.log -O delgroup.out '<https://www.example.com/sites/all/modules/civicrm/extern/rest.php?entity=group&action=delete&key=site-key&api_key=api-key&version=3&json=1&id=923>'
  
  **Tags:** database, smartgroups
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_1 on 2015-10-08. Score: 2
  
  I suggest you use the api.
  
  Visiting yoursite.org/civicrm/api will let you try it out.
  
  > **Comments:**
  > **username_0**: That link just takes me to the dashboard  
  > **username_1**: Maybe you are using an older version of Civi. Try yoursite.org/civicrm/api/explorer  
  > **username_0**: That worked but I have never written any php using the API. What I've got is a spreadsheet with a list of group ids I want to delete. There are about 400 of them so I really want to write a script. It looks like the API will do the trick and remove members from the groupas well but I need to find an example of how to write the PHP. This is CiviCRM 4.1.5.  We are migrating to Nation Builder and need to delete these groups before the migration.  
  > **username_0**: Sorry...I cannot figure out how to put code in the comments  
  > **username_1**: Sorry to lose you to NB - enjoy their new higher prices.  
  
  ---
  
  ### Answer by username_2 on 2015-10-12. Score: 1
  
  The challenge seems to be instantiating civicrm within a script - the easiest ways are
  
  1) through the api explorer
  2) through drush - ie drush eval"civicrm\_initialize(); script lines here"
  3) through devel in the UI looks much like drush
  
  Otherwise for a standalone php script (that doesn't leverage drupal) you probably want to copy the way one of the scripts in the bin directory does it - but that way is more painful :-(
  
  > **Comments:**
  > **username_0**: This has to be run on a production system that does not have Drush installed, otherwise I could do it with Drush. I have seen other posts that other people had problems with CiviCRM initialize too  
  > **username_0**: Haha. I was looking for something not too painful for a newb.  
  > **username_0**: I'd still like to know how to do it with a standalone php script using the API  
  > **username_0**: While Eileen's answer was informative, I still was not able to write a php script using the API directly.  
  
  ---
  
  ### Answer by username_0 on 2015-10-14. Score: 0
  
  I got it to work by calling rest.php with wget wget -a delgroup.log -O delgroup.out 'example.com/sites/all/modules/civicrm/extern/…;
  
  
  ---
  
  ### Answer by username_2 on 2015-10-12. Score: 0
  
  You could also use chaining in the api explorer ie.
  
  civicrm\_api3('Group', 'get', array('id' => array('IN' => array(4,6,7,8,9), 'api.group.delete');
  
  But test thoroughly on dev first!!!
  
  > **Comments:**
  > **username_3**: if that is the 'solution' then suggest you add as an answer ;-)  
  
  ---
  
  