There is Rest API to create and update the categories in Magento.
Using one attribute we can disable and enable showing the products of sub-categories on the parent category page in magento2
That can be done using
is_anchor: 0
This will disable the listing of products on parent category.
is_anchor: 1
This will enable the listing of products in the parent category.
Thank you.