photools.com Community

IMatch Discussion Boards => IMatch Scripting and Apps => Topic started by: nordkapp on October 21, 2018, 12:08:23 AM

Title: Return a category and all its child categories
Post by: nordkapp on October 21, 2018, 12:08:23 AM
I have a category with 2 child categories which also have child categories

I want to get the IDs of the category and all its childs. As I unterstand the documentation I have to use code like this:

                IMatch.get('v1/categories',{
                    path: 'QS|CaptureOne Rating',
                    fields: 'id,name',
                    recursive: true
                }).then(function(response) {
                    console.log (response);
                });

But I only get the one selected category back. No child categories are in the response.

The output is:

{
  "categories": [
    {
      "id": 3257,
      "name": "CaptureOne Rating"
    }
  ]
}


Did I miss something?
Title: Re: Return a category and all its child categories
Post by: thrinn on October 21, 2018, 09:50:26 AM
The call looks correct to me. It SHOULD return all child categories.
But I can reproduce the results you see here. I suspect there might be some bug in the combination with the "fields" parameter:
Title: Re: Return a category and all its child categories
Post by: nordkapp on October 21, 2018, 11:32:31 AM
Thanks Thorsten, if I ommit the fields parameter it works here to.

But I must say I am a little overwhelmed from the result. I thought I try to learn a little bit javascript by iteration over all (sub-)categories and unassign all files from them. Actually I delete the category first and recreate it each time my sript runs. Thats seem a bit "brutal" but it works. So for now I stay with it and work on other parts of my scripts
Title: Re: Return a category and all its child categories
Post by: Mario on October 21, 2018, 01:03:12 PM
The recursive parameter only has an impact if you request information about the child categories.
If you don't use fields or if you include 'children' in fields.

If you don't request the children field, no data about children is returned. recursive then controls how deep the returned hierarchy is (only the children of the requested categories or down to the bottom level).

For example:

(https://www.photools.com/community/index.php?action=dlattach;topic=8418.0;attach=20275;image)

requests the id and name for the category Numbers, and also for all children, recursively).

The result looks like this:

(https://www.photools.com/community/index.php?action=dlattach;topic=8418.0;attach=20277;image)
Title: Re: Return a category and all its child categories
Post by: thrinn on October 21, 2018, 09:02:30 PM
Ah, I see. I was not aware of that. So I learned something new today!
One of the many advantages of using IMatch is that such questions are answered by the developer himself who knows exactly what's going on.  ;)
Title: Re: Return a category and all its child categories
Post by: Mario on October 21, 2018, 09:20:34 PM
Was never different.