Return a category and all its child categories

Started by nordkapp, October 21, 2018, 12:08:23 AM

Previous topic - Next topic

nordkapp

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?

thrinn

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:

  • If I do NOT specify the fields parameter, the result contains all children.
  • If I specify the fields parameter, only the category specified in the call is returned
Thorsten
Win 10 / 64, IMatch 2018, IMA

nordkapp

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

Mario

#3
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:



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

The result looks like this:

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

thrinn

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.  ;)
Thorsten
Win 10 / 64, IMatch 2018, IMA

Mario

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