Author Topic: Remove all bookmarks  (Read 183 times)

hkae

  • New Members
  • *
  • Posts: 16
Remove all bookmarks
« on: March 16, 2019, 09:46:42 AM »
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

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 22281
Re: Remove all bookmarks
« Reply #1 on: March 16, 2019, 10:33:58 AM »
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

hkae

  • New Members
  • *
  • Posts: 16
Re: Remove all bookmarks
« Reply #2 on: March 16, 2019, 11:00:54 AM »
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

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 22281
Re: Remove all bookmarks
« Reply #3 on: March 16, 2019, 11:04:25 AM »
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:

Code: [Select]
// 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:

« Last Edit: March 16, 2019, 11:24:31 AM by Mario »

hkae

  • New Members
  • *
  • Posts: 16
Re: Remove all bookmarks
« Reply #4 on: March 16, 2019, 12:39:59 PM »
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

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 22281
Re: Remove all bookmarks
« Reply #5 on: March 16, 2019, 12:59:26 PM »
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.