API Support for Collapsing Layers in Plugins

Hello, I am currently facing an issue where I would like to use an API within a plugin to collapse the right-side node tree. However, I have only found the Option+L shortcut, and there seems to be no available API to accomplish this. Is there another way to achieve this functionality? It is very important to me. Thank you!