<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body dir="auto">
<div>Note that that is a DELETE EVERYTHING method. If that not what you want, you need to replace the all_ids curl with a search or something that gets you the ids of items to be deleted. <br>
<br>
Sent from my iPhone</div>
<div><br>
On Sep 14, 2016, at 6:26 PM, Majewski, Steven Dennis (sdm7g) <<a href="mailto:sdm7g@eservices.virginia.edu">sdm7g@eservices.virginia.edu</a>> wrote:<br>
<br>
</div>
<blockquote type="cite">
<div>
<div class="">How to delete stuff using the API:</div>
<div class=""><br class="">
</div>
<div class="">I haven’t had to try to delete locations, but the principle is the same for most resources. </div>
<div class="">Locations are global, not repository based, so you don’t need the /repositories/$REPO_ID in the URL. </div>
<div class=""><br class="">
</div>
<div class="">Try  /locations/$ID instead of /repositories/$REPO_ID/$THING/$ID. </div>
<div class=""><br class="">
</div>
<div class="">This was originally written for deleting resources, but I changed it to delete digital_objects ( which don’t get deleted when their owner resource gets deleted. ) I’ve added some annotations to explain. </div>
<div class=""><br class="">
</div>
<div class="">If you don’t have ‘jq’ installed, you can leave that out. It’s just used to pretty-print the JSON output. </div>
<div class=""><br class="">
</div>
<div class="">— Steve Majewski</div>
<div class=""><br class="">
</div>
<div class=""># [1] set variables:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">REPO=<a href="http://localhost:4567" class="">http://localhost:4567</a></span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">#</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">REPO_ID=$1</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">THING=digital_objects</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">#</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">user=</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">pass=</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
# [2] clip out the login logic from scripts/curl_as or scripts/curl_as_osx </div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
# If you’re going to repeat this call thousands of times, it’s better to just do it once at the start</div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
# rather than call those scripts and do it many times...</div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">session=$(curl -s -F password="$pass" "$REPO/users/$user/login" |</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">    sed 's|.*"session":"\([a-z0-9]*\)".*|\1|g')</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">echo "Repo: $REPO/repositories/$REPO_ID" </span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">echo "Session $session" 1>&2</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
# [3] Are you sure ? </div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">curl -H "X-ArchivesSpace-Session: $session" "$REPO/repositories/$REPO_ID" | jq . </span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">echo -n "Delete all $THING from this repo? [Y/N]: "; read ANS </span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">if [ "$ANS" = "Y"  ]</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">then</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
# [4] get the list of resources using "?all_ids=true” </div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
# this returns a list of IDs. Strip off the “[“, “]” and “,” and iterate over IDs:</div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
# do a DELETE on each resource ID. </div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">DELETE='-X DELETE'</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">for ID in $( curl  -H "X-ArchivesSpace-Session: $session" "$REPO/repositories/$REPO_ID/${THING}?all_ids=true" | tail -1 | tr '[],' ' ' )</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">do</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">curl -H "X-ArchivesSpace-Session: $session" $DELETE $REPO/repositories/$REPO_ID/$THING/$ID | jq . </span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">done</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">fi</span></div>
<div style="margin: 0px; font-size: 15px; line-height: normal; background-color: rgb(189, 238, 237); min-height: 18px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<br class="">
<blockquote type="cite" class="">On Sep 14, 2016, at 5:52 PM, <a href="mailto:library@princeofpeaceabbey.org" class="">
library@princeofpeaceabbey.org</a> wrote:<br class="">
<br class="">
Jason,<br class="">
<br class="">
I too have this problem. I deleted the locations that I did not want from MySql but they still show up. Tried to delete them from AS but It refused. So if you can put the answer in easy to follow directions I would be happy.<br class="">
<br class="">
Br Raphael<br class="">
Quoting Jason Loeffler <<a href="mailto:j@minorscience.com" class="">j@minorscience.com</a>>:<br class="">
<br class="">
<blockquote type="cite" class="">Hi Lydia,<br class="">
You can iterate over the desired location end points via the API and perform a delete operation. Let me know if you need help setting this up. <br class="">
JL<br class="">
--<br class="">
Jason Loeffler<br class="">
Technology Consultant | The American Academy in Rome<br class="">
Minor Science | Application Development & Metadata Strategy<br class="">
Brooklyn, New York<br class="">
<a href="mailto:jason@minorscience.com" class="">jason@minorscience.com</a><br class="">
(347) 405-0826<br class="">
minorscience (Skype)<br class="">
<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>_____________________________<br class="">
From: Tang, Lydia <<a href="mailto:ltang5@mail.lib.msu.edu">ltang5@mail.lib.msu.edu</a>><br class="">
Sent: Wednesday, September 14, 2016 14:56<br class="">
Subject: [Archivesspace_Users_Group] location woes<br class="">
To:  <<a href="mailto:archivesspace_users_group@lyralists.lyrasis.org">archivesspace_users_group@lyralists.lyrasis.org</a>><br class="">
<br class="">
<br class="">
Hello everyone,<br class="">
I’ve definitely learned to try out my more ambitious projects in our test instance after this location snafu.  We tried to roll back the instance to a backup last night, reindexed everything, and the bad locations were all still there!  If any of you know of
 a way to target mass delete the locations (nearly 6500 location entries), please let me know!<br class="">
Lydia<br class="">
_______________________________________________<br class="">
Archivesspace_Users_Group mailing list<br class="">
<a href="mailto:Archivesspace_Users_Group@lyralists.lyrasis.org">Archivesspace_Users_Group@lyralists.lyrasis.org</a><br class="">
<a href="http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group">http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group</a><br class="">
</blockquote>
<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
Archivesspace_Users_Group mailing list<br class="">
<a href="mailto:Archivesspace_Users_Group@lyralists.lyrasis.org" class="">Archivesspace_Users_Group@lyralists.lyrasis.org</a><br class="">
<a href="http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group">http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group</a><br class="">
</blockquote>
<br class="">
</div>
</blockquote>
<blockquote type="cite">
<div><span>_______________________________________________</span><br>
<span>Archivesspace_Users_Group mailing list</span><br>
<span><a href="mailto:Archivesspace_Users_Group@lyralists.lyrasis.org">Archivesspace_Users_Group@lyralists.lyrasis.org</a></span><br>
<span><a href="http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group">http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group</a></span><br>
</div>
</blockquote>
</body>
</html>