Stikkit Forums
November 19, 2008, 03:31:07 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: SMF - Just Installed
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Deleting multiple stikkits  (Read 3348 times)
mariuswatz
Member
*

Karma: 0
Posts: 9


« on: April 10, 2007, 03:51:06 AM »

Is there a way to delete multiple Stikkits with a single API call?
Logged
altano
Member
*

Karma: 0
Posts: 5


« Reply #1 on: April 18, 2007, 09:24:04 PM »

An import-gone-bad has made it so that I need to do this as well:
http://community.valuesofn.com/stikkit/index.php/topic,443.0.html

I don't think this can be done without having to roll up my sleeves...
Logged
mariuswatz
Member
*

Karma: 0
Posts: 9


« Reply #2 on: April 22, 2007, 01:35:32 PM »

Deleting a bunch of stikkits is not that hard, it just needs a separate call for each stikkit. The following PHP code should do the trick. Simply fill in API key and use at YOUR OWN RISK. You need to uncomment the deleteStikkit line to make the script do the deletions. The script must be called repeatedly until no more stikkits are found.

You can filter by kind or tag, but I have found inconsistent results when using kind. If you are simply after deleting calendar entries, I suggest uncommenting the line that forces the script to work with calendar entries.

You will also need two PHP packages: HTTP_Request and Services_JSON.

Code:
<?php
ini_set
("include_path"ini_get('include_path').";./PEAR;C:/aCode/PHP/");
require_once 
"HTTP/Request.php";
require_once 
"JSON/JSON.php";

$apikey="api_key=xxxx";
$EVENTS=2;
$TODOS=128;
$PEEPS=32;
$BOOKMARKS=1;

// delete all events found
deleteAllStikkits(1,null,$EVENTS);

function 
deleteAllStikkits($page=1,$tag=null,$stikkitKind=255) {
global $apikey;

$param="page=$page&kind=$stikkitKind";
if(isset($tag)) $param.="&tags=$tag";

      
// uncomment the next line to make the request work with only calendar stikkits
//$reqstr="http://api.stikkit.com/calendar?$apikey&$param";
      // uncomment the next line to make the request work for all stikkits
       
$reqstr ="http://api.stikkit.com/stikkits?$apikey&$param";

$req =& new HTTP_Request($reqstr);


$req->setMethod(HTTP_REQUEST_METHOD_GET);
$req->addHeader("Accept""application/json, */*");

$res=stikkitAPI($req);
$num=sizeof($res);

echo("<p>$reqstr<br />$num stikkits found.</p>");
for($i=0$i<$num$i++) {
echo("Would have deleted stikkit ID ".$res[$i]["id"]." - ".$res[$i]["name"]."<br />\n");

// uncomment to delete the stikkit.
// deleteStikkit($res[$i]["id"]);
}
}

function 
stikkitAPI($req) {
$response $req->sendRequest();

if (PEAR::isError($response)) echo $response->getMessage();
else {
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
    $value $json->decode($req->getResponseBody());
return $value;
}
}

function 
deleteStikkit($id) {
global $apikey;
$req =& new HTTP_Request("http://api.stikkit.com/stikkits/$id?$apikey");
$req->setMethod(HTTP_REQUEST_METHOD_DELETE);
$res=stikkitAPI($req);
echo("<p>Deleted stikkit: $id</p>\n");
}

?>
« Last Edit: April 22, 2007, 04:51:52 PM by mariuswatz » Logged
thomking
Member
*

Karma: 0
Posts: 6


WWW
« Reply #3 on: May 16, 2007, 04:46:00 AM »

Deleting a bunch of stikkits is not that hard, it just needs a separate call for each stikkit. The following PHP code should do the trick. Simply fill in API key and use at YOUR OWN RISK. You need to uncomment the deleteStikkit line to make the script do the deletions. The script must be called repeatedly until no more stikkits are found.

You can filter by kind or tag, but I have found inconsistent results when using kind. If you are simply after deleting calendar entries, I suggest uncommenting the line that forces the script to work with calendar entries.

You will also need two PHP packages: HTTP_Request and Services_JSON.

Code:
<?php
ini_set
("include_path"ini_get('include_path').";./PEAR;C:/aCode/PHP/");
require_once 
"HTTP/Request.php";
require_once 
"JSON/JSON.php";

$apikey="api_key=xxxx";
$EVENTS=2;
$TODOS=128;
$PEEPS=32;
$BOOKMARKS=1;

// delete all events found
deleteAllStikkits(1,null,$EVENTS);

function 
deleteAllStikkits($page=1,$tag=null,$stikkitKind=255) {
global $apikey;

$param="page=$page&kind=$stikkitKind";
if(isset($tag)) $param.="&tags=$tag";

      
// uncomment the next line to make the request work with only calendar stikkits
//$reqstr="http://api.stikkit.com/calendar?$apikey&$param";
      // uncomment the next line to make the request work for all stikkits
       
$reqstr ="http://api.stikkit.com/stikkits?$apikey&$param";

$req =& new HTTP_Request($reqstr);


$req->setMethod(HTTP_REQUEST_METHOD_GET);
$req->addHeader("Accept""application/json, */*");

$res=stikkitAPI($req);
$num=sizeof($res);

echo("<p>$reqstr<br />$num stikkits found.</p>");
for($i=0$i<$num$i++) {
echo("Would have deleted stikkit ID ".$res[$i]["id"]." - ".$res[$i]["name"]."<br />\n");

// uncomment to delete the stikkit.
// deleteStikkit($res[$i]["id"]);
}
}

function 
stikkitAPI($req) {
$response $req->sendRequest();

if (PEAR::isError($response)) echo $response->getMessage();
else {
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
    $value $json->decode($req->getResponseBody());
return $value;
}
}

function 
deleteStikkit($id) {
global $apikey;
$req =& new HTTP_Request("http://api.stikkit.com/stikkits/$id?$apikey");
$req->setMethod(HTTP_REQUEST_METHOD_DELETE);
$res=stikkitAPI($req);
echo("<p>Deleted stikkit: $id</p>\n");
}

?>

i used this code its showing a null pointer exception
Logged

mariuswatz
Member
*

Karma: 0
Posts: 9


« Reply #4 on: May 18, 2007, 02:41:03 AM »

i used this code its showing a null pointer exception

Did you enter your own API key into the script? What is the exact error message you're getting?
Logged
thomking
Member
*

Karma: 0
Posts: 6


WWW
« Reply #5 on: July 18, 2007, 08:46:14 AM »

Quote
Did you enter your own API key into the script?

Yes I enterted!

Quote
What is the exact error message you're getting?
How can I express here?
Logged

thomking
Member
*

Karma: 0
Posts: 6


WWW
« Reply #6 on: August 25, 2007, 04:25:53 AM »

no response!
needs suggestion!
thanks in advance!
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.1 | SMF © 2006, Simple Machines LLC Valid XHTML 1.0! Valid CSS!