{"action":"closed","issue":{"url":"https://api.github.com/repos/hypothesis/h/issues/2333","labels_url":"https://api.github.com/repos/hypothesis/h/issues/2333/labels{/name}","comments_url":"https://api.github.com/repos/hypothesis/h/issues/2333/comments","events_url":"https://api.github.com/repos/hypothesis/h/issues/2333/events","html_url":"https://github.com/hypothesis/h/issues/2333","id":90492174,"number":2333,"title":"Can't delete annotations created in a different session","user":{"login":"bbarker","id":916366,"avatar_url":"https://avatars.githubusercontent.com/u/916366?v=3","gravatar_id":"","url":"https://api.github.com/users/bbarker","html_url":"https://github.com/bbarker","followers_url":"https://api.github.com/users/bbarker/followers","following_url":"https://api.github.com/users/bbarker/following{/other_user}","gists_url":"https://api.github.com/users/bbarker/gists{/gist_id}","starred_url":"https://api.github.com/users/bbarker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bbarker/subscriptions","organizations_url":"https://api.github.com/users/bbarker/orgs","repos_url":"https://api.github.com/users/bbarker/repos","events_url":"https://api.github.com/users/bbarker/events{/privacy}","received_events_url":"https://api.github.com/users/bbarker/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-23T21:17:50Z","updated_at":"2015-07-09T16:22:36Z","closed_at":"2015-07-09T16:22:36Z","body":"Hi All,\r\n\r\nHere is an example code to demonstrate. It uses a single user to try to delete an existing annotation, which, for me, fails. Then, it uses the same type of code to create and then delete and annotation, which succeeds:\r\n\r\n```perl\r\n#!/usr/local/bin/perl -w\r\n\r\nuse Hypothesis::API;\r\n\r\nmy $user = 'arXiv';\r\nmy $pword_file = \"password.txt\";\r\n\r\n#\r\n# I suspect that this is related to creating an id in a different session\r\n# Let's try to delete an existing id first\r\n#\r\n\r\nmy $id = \"vjiQgN-UTWuAc9jwcOJFBg\";\r\n\r\nopen(my $pword_fh, '<:encoding(UTF-8)', $pword_file)\r\n    or die \"Couldn't open password file: '$pword_file' $!\";\r\nmy $pword = <$pword_fh>;\r\nchomp $pword;\r\n\r\nmy $H = Hypothesis::API->new($user, $pword);\r\nnot $H->login or die \"Exiting due to failed login.\\n\";\r\n\r\nif( $H->delete_id($id) ) {\r\n    print(\"Deletion of newly created annotation successful.\");\r\n} else {\r\n    warn(\"Unable to delete newly created annotation while authenticated!\");\r\n}\r\n\r\n\r\n#\r\n# Now let's try the exact same code, but with a newly created id:\r\n#\r\n\r\nmy $payload = {\r\n    \"uri\"  => 'http://arxiv.org/abs/0704.0009',\r\n    \"text\" => \"testing create in hypothes.is API\"\r\n};\r\n\r\nmy $new_id = $H->create($payload);\r\n\r\nwarn(\"Waiting 10 seconds to allow checking the webpage.\");\r\nsleep(10);\r\n\r\nif( $H->delete_id($new_id) ) {\r\n    print(\"Deletion of newly created annotation successful.\");\r\n} else {\r\n    warn(\"Unable to delete newly created annotation while authenticated!\");\r\n}\r\n```\r\n\r\nNote that for demonstration purposes, I may be deleting the annotation with id `vjiQgN-UTWuAc9jwcOJFBg`, so here is what it looks like at the moment:\r\n\r\n```json\r\n        {\r\n            \"updated\": \"2015-06-23T20:51:09.641730+00:00\", \r\n            \"target\": {\r\n                \"selector\": [\r\n                    {\r\n                        \"start\": null, \r\n                        \"end\": null, \r\n                        \"type\": \"TextPositionSelector\"\r\n                    }, \r\n                    {\r\n                        \"type\": \"TextQuoteSelector\", \r\n                        \"prefix\": null, \r\n                        \"exact\": null, \r\n                        \"suffix\": null\r\n                    }\r\n                ]\r\n            }, \r\n            \"created\": \"2015-06-23T20:51:09.641686+00:00\", \r\n            \"text\": \"testing create in hypothes.is API\", \r\n            \"tags\": null, \r\n            \"uri\": \"http://arxiv.org/abs/0704.0009\", \r\n            \"user\": \"acct:arXiv@hypothes.is\", \r\n            \"document\": {}, \r\n            \"consumer\": \"00000000-0000-0000-0000-000000000000\", \r\n            \"id\": \"vjiQgN-UTWuAc9jwcOJFBg\", \r\n            \"permissions\": {\r\n                \"admin\": [\r\n                    \"acct:arXiv@hypothes.is\"\r\n                ], \r\n                \"read\": [\r\n                    \"group:__world__\"\r\n                ], \r\n                \"update\": [\r\n                    \"acct:arXiv@hypothes.is\"\r\n                ], \r\n                \"delete\": [\r\n                    \"acct:arXiv@hypothes.is\"\r\n                ]\r\n            }\r\n        }, \r\n```\r\n\r\nIt should be easy to change the script to work with a different user and annotation id in the obvious ways. If you aren't very familiar with Perl, here's a quick way to install the module:\r\n\r\n```\r\nsudo apt-get install cpanminus\r\nsudo cpanm -i Hypothesis::API\r\n```\r\n\r\n\r\nAnd, here is what the output of the script looks like:\r\n\r\n```\r\n./delete_id.pl\r\nTrouble decoding JSON: garbage after JSON object, at character offset 4 (before \"Forbidden\\n\\nAccess ...\") at /opt_arxiv/perl/lib/site_perl/5.12.4/Hypothesis/API.pm line 272, <$pword_fh> line 1.\r\n\r\n403 Forbidden\r\n\r\nAccess was denied to this resource.\r\n\r\n\r\nUnauthorized: delete failed permission check\r\n\r\nUnable to delete newly created annotation while authenticated! at ./delete_id.pl line 25, <$pword_fh> line 1.\r\nWaiting 10 seconds to allow checking the webpage. at ./delete_id.pl line 40, <$pword_fh> line 1.\r\nDeletion of newly created annotation successful.\r\n```"}}