Remove all bookmarks

Started by hkae, March 16, 2019, 09:46:42 AM

Previous topic - Next topic

hkae

I struggle with the syntax of the post v1/collections object.
I have created a export app which exports either all selected or all bookmarked images. For the export I use the functionality the  image processor offers. After all images are exported I would like to remove all bookmarks. But so far I struggle with the correct syntax of the collection object  (id=2).
There is a hint within the API description about a separate document which describes this object. But so far I did not manage to find this documentation.
I would be thankful for a link to this documentation or a code sample which shows how I could remove all bookmarks.
Thanks for any help or code samples.

Mario

Did you look at the Collections example app?`
It shows how to add and remove files to/from the bookmarks collection.

Look at line 242 and following.

The documentation you are looking for is in the IMatch Developer Center.
Check out the Tutorial and Recipies topic:

https://www.photools.com/dev-center/doc/imatch/tutorial-recipes.html

Scroll down to the headline which reads Working with Collections
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

hkae

Thanks for your fast response. I have seen this documentation but I was not sure if there is an additional one and yes of course I used your sample app to learn and understand how to call the iMatch v1/collections endpoint:

IMWS.post('v1/collections',params).then(function(response) {....},
                    function(error){
                        alert("Fehler beim löschen der Lesezeichen");
                    });

If I debug my app I submit the following params:  [{"id":"2","op":"remove"] } together with the auth_token which fails...
The result tells me that I use a wrong syntax... but so far all my tries to modify my params list failed as well.
Thats why I asked If there is a specific documentation which explains the syntax of the post remove object.

Mario

#3
id means a single file id or list of ids.
Which path do you use in your task? Show us the full code.

Does the Collection example work on your system?
It removes all selected files from Bookmarks.
You can just copy the code and replace the idlist with id and list the files you want to remove.
To remove all files from the Bookmarks collection first retrieve the list of files in that collection and supply the resulting list of file ids.

This code retrieves the ids of all files in Bookmarks and then removes them from the collection:


// Get the id of all files in the Bookmarks collection
IMWS.get('v1/collections/files',{
    path : 'Bookmarks',
    fields: 'id'
}).then(function(response) {
    // Uncomment these to see the response in the browser console
    //console.log(JSON.stringify(response));
    //console.log(JSON.stringify(response.collections[0].files));

    let params = {
        // The list of file ids to remove.
        // We use the list of ids retrieved above
        id: response.collections[0].files.join(','),

        // What to do with these files?
        tasks: JSON.stringify(
            [{
                'op' : 'remove',
                'path' : 'Bookmarks'
            }]
        )
    }
   
    // Send the request
    IMWS.post('v1/collections',params).then(function(response) {
        console.log(response);
    },error => {
        console.log(error);
    });


The same code with highlighting, for better reference if another user finds this later:

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

hkae

Thanks Mario,

Your sample works perfect!! 

I understand my mistake now: I misunderstood the collection parameter id. I assumed the collection id would be the collection number (which resulted in my code to the assumption id=2 means Bookmark which represented the collection I wanted to remove all images). For the files I tried parameter names like fileid and fileids.... which generated the syntax errors.

Thanks again for your help and the sample code which!

Mario

The docs were wrong about the actions parameter (I renamed them all to tasks a while ago but somehow missed this one).
But the is is documented correctly as "The files to add or remove to/from the collection. Use either id, idlist or path."

Working with collections, metadata and Attributes is a tad more complex than other endpoints. This is because these endpoints have designed to be fast, to allow apps to do a lot of things with one endpoint call. IMWS can optimize all the operations, wrap them into one database transaction. This greatly enhances performance. Especially for the metadata endpoints.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook